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
class Entity
{
[Column(TypeName = "jsonb")]
public BaseType Config {get;set;}
}
And a number of types derived from BaseType:
public class Derived1 : BaseType { public string StringProp {get;set;} }
public class Derived2 : BaseType { public int IntProp {get;set;} }
... etc you got the idea.
Is this possible to achieve?
I tried to configure a custom ValueConverter<BaseType, JsonDocument> and conversion to JsonDoument was easy.
Conversion from JsonDocument can be tricky as JsonDocument doesn't contain a ContainsKey method or similar but doable.
Missing part is querying as Where(x => ((Dervived)x.Config).IntProp == 1) couldn't be translated.
The text was updated successfully, but these errors were encountered:
This currently isn't supported out of the box, since it would require some strategy of storing the type inside the JSON document in some way (i.e. is it a Derived1 or a Derived2?). This is typically done by introducing some sort of discriminator property (like EF Core already does for Type-Per-Hierarchy mapping, see docs), but nothing like this is supported for JSON at the moment.
Some serious work on JSON is planned for EF Core 7.0 - I'll make sure we have this on our radar, though it definitely isn't a guarantee this would be supported for that version.
Hello, I have a table entity like this:
And a number of types derived from BaseType:
... etc you got the idea.
Is this possible to achieve?
I tried to configure a custom ValueConverter<BaseType, JsonDocument> and conversion to JsonDoument was easy.
Conversion from JsonDocument can be tricky as JsonDocument doesn't contain a ContainsKey method or similar but doable.
Missing part is querying as Where(x => ((Dervived)x.Config).IntProp == 1) couldn't be translated.
The text was updated successfully, but these errors were encountered: