You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This json data field is unstable but with some fields that seems exists in all instances. These json data were extracted from a third-party service tool so we don't have any control on it. I want to preserve the original data while having a proxy property just for LINQ-querying because using JsonDocument mapping is quite tedious, some fields that I need are from great grandchild: var records = this.dbSet.AsQueryable().Where(r => r.Data.RootElement.GetProperty("Properties").GetProperty("MetaData").GetProperty("Provider").GetProperty("Name").GetString() == "AWS").ToList();
I tried to create an unmapped property as proxy(MappedData) by ignoring it in fluent API(I wrote these codes by hand because my work laptop got limited internet connection):
class Log {
public Guid Id {get;set;}
public DateOnly Date {get;set;}
public JsonDocument Data {get;set;
public MappedJsonData MappedData{
get => JsonSerializer.Deserialize(this.Data);
set => this.Data = JsonSerializer.SerializeToDocument(value);
}
}
It translates fine to the result, but not if used in filtering like in Where clause: var records = this.dbSet.AsQueryable().Where(r => r.MappedData.Properties.MetaData.Provider.Name == "AWS").ToList();
I'm getting an error related to MappedData that it can't get translated because it is unmapped.
I tried to use Newtonsoft's JSON.NET because it seems easier to perform LINQ queries and not that tedious. Even after I applied the extension UseJsonNet() and replaced the type of Data to JObject.
Thanks!
The text was updated successfully, but these errors were encountered:
I'm not sure I follow what you're trying to do... Do you want to use your "proxy property" to somehow express queries over your real column in the database? Do you want the structure of the proxy property to somehow be nicer than your actual data? How would EF know what actual SQL query to generate?
A full, clearer code sample showing what you're trying could help here.
This json data field is unstable but with some fields that seems exists in all instances. These json data were extracted from a third-party service tool so we don't have any control on it. I want to preserve the original data while having a proxy property just for LINQ-querying because using JsonDocument mapping is quite tedious, some fields that I need are from great grandchild:
var records = this.dbSet.AsQueryable().Where(r => r.Data.RootElement.GetProperty("Properties").GetProperty("MetaData").GetProperty("Provider").GetProperty("Name").GetString() == "AWS").ToList();
I tried to create an unmapped property as proxy(MappedData) by ignoring it in fluent API(I wrote these codes by hand because my work laptop got limited internet connection):
class Log {
public Guid Id {get;set;}
public DateOnly Date {get;set;}
public JsonDocument Data {get;set;
public MappedJsonData MappedData{
get => JsonSerializer.Deserialize(this.Data);
set => this.Data = JsonSerializer.SerializeToDocument(value);
}
}
It translates fine to the result, but not if used in filtering like in Where clause:
var records = this.dbSet.AsQueryable().Where(r => r.MappedData.Properties.MetaData.Provider.Name == "AWS").ToList();
I'm getting an error related to MappedData that it can't get translated because it is unmapped.
I tried to use Newtonsoft's JSON.NET because it seems easier to perform LINQ queries and not that tedious. Even after I applied the extension UseJsonNet() and replaced the type of Data to JObject.
Thanks!
The text was updated successfully, but these errors were encountered: