-
Notifications
You must be signed in to change notification settings - Fork 473
Description
Like (i suspect) most people using WebApi with OData I back my OData models with EF Models in the storage tier.
I can have entities with computed values or as mentioned in the title a column in the DB that stores a json blob that's mapped to a complex type but isn't an "entity type with a key as such".
So my question here is ...
How can map something (either strongly typed or dynamic) that's stored in a DB row in such a way that I can retain the full OData querying functionality on it?
I ask this now because newer versions of SQL now have a JsonColumn type (much like the old XML column type which I also don't know how to map).
Here's an example of what I would like to "OData query, ideally with the expression tree that's computed running entirely in the DB" ...
public class Foo
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
string data;
public IDictionary<string, object> Data
{
get { return JsonConvert.DeserializeObject<IDictionary<string, object>>(data); }
set { data = JsonCvonert.SerializeObject(value); }
}
}
The docs show that this data can be returned as per the open types description but i'm looking to quey the base set based on this open data too ...
https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4
This situation will work and is perfectly map-able under EF but from what I understand if I do this I can't query OData in such a way that I could (for example) get a list of Foo objects where some value in the dictionary was a filter or sort criteria for the set I wanted to return.
The only option I have is to define this as a child entity then I'm adding a new primary, and foreignkey in to the new "type" and replacing the dictionary with a collection to join to but to my knowledge most SQL implementations can store this and query within it fine today ...
Here's what i'm looking to take advantage of through an OData query ...
... whilst I do accept this is not a great example, I have a situation that's more specific to my business that I would happily discuss if you guys need more context for this question.