linq2db.EntityFrameworkCore icon indicating copy to clipboard operation
linq2db.EntityFrameworkCore copied to clipboard

Inherited Include not populated?

Open Evengard opened this issue 4 years ago • 3 comments

Let's assume I have theese entities:

public class Base
{
    public Guid Id {get; set;}
    [ForeignKey("Other")]
    public Guid OtherId {get; set;}
    public Other Other {get; set;}
}

public class Inherited : Base
{
    public string SomeValue {get; set;}
}

public class Other
{
    public Guid Id {get; set;}
    [InverseProperty("Other")]
    public virtual ICollection<Base> Values {get; set;}
}

Now, I have 1 element of type Other and 1 element of type Inherited, having a relation between themselves. The query

_context.Others
.Include(o => o.Values)
.ToArrayAsyncLinqToDB()

mostly works but with one catch. When iterating over Other.Values they are all retrieved as "Base" from db, not as "Inherited", so I can't cast them to "Inherited". The same query done by EF Core makes them "Inherited" so I can cast them. What am I doing wrong?

Evengard avatar Jul 01 '21 15:07 Evengard

I guess this falls under the "hierarchy per table" thing which isn't really supported, right?

Evengard avatar Jul 28 '21 12:07 Evengard

No idea how inheritance mapping configured in EF.Core, but:

  1. linq2db needs discriminator field to distinguish Base from Inherited
  2. I don't see any inheritance-related stuff configured in EF.Core to linq2db mapping code here

MaceWindu avatar Jul 28 '21 13:07 MaceWindu

Well, EF Core itself does create a "Discriminator" field in the database itself...

Evengard avatar Jul 29 '21 00:07 Evengard