How to use inherited properties in EF Core expressions?

后端 未结 1 1015
天涯浪人
天涯浪人 2020-12-11 20:21

We need construct expression for EF in dynamic way. For example create test models:

public class TestBase
{
    public int Id { get; set; }
}

public class T         


        
相关标签:
1条回答
  • 2020-12-11 20:46

    Wow, this sounds like another EF Core bug (happens also in v.1.1.0 (release)).

    The only difference between the two expressions is the ReflectedType of the property accessor expression Member.

    You can fix it this way:

    // ...
    var p = e.Type.GetProperty("Id");
    if (p.ReflectedType != p.DeclaringType)
        p = p.DeclaringType.GetProperty(p.Name);
    Expression bin = Expression.MakeMemberAccess(e, p);
    // ...
    

    but it's weird to have such requirement, I would suggest reporting the issue to EF Core GitHub.

    0 讨论(0)
提交回复
热议问题