Skip to content

Json POCO mapping and type hierarchy #2321

@forik

Description

@forik

Hello, I have a table entity like this:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions