How can I configure DbSet with an ICollection<T> in DbSet<Element<T>>

33 Views Asked by At

I have a Domain as described below;

Can I configure EntityFramework to have a single table for Elements and a single table for both ItemA and ItemB???

public class Element<T> where T : ItemBase
{
    public Guid Id { get; set; }
    public string Name { get; set; } 
    public ICollection<T> Items { get; set; }
}

public class ItemA : ItemBase
{
    ItemA(Guid id, string name): base(id, name)
}

public class ItemB : ItemBase
{
    ItemB(Guid id, string name): base(id, name)
}

public class ItemBase
{
    public Guid Id { get; set; }
    public string Name { get; set; } 
}

Can I configure

So far the only suggestion that makes any sense is to use a [Table] attribute on the Element class but I'm sure there's a better way configuring DbSet<> correctly...

0

There are 0 best solutions below