我在Entity Framework中遇到Include()问题。

我有一些实体

public partial class Travel_RequestEmployee
{
 public virtual Traveler Traveler { get; set; }
}

public abstract partial class Traveler{
}

public partial class Traveler_Employee : Traveler
{
 public virtual Employee Employee { get; set; }
}


我想包括Travel_RequestEmployee中的员工属性。有没有办法让Include()像这样工作?

_context.Travel_RequestEmployee.Include(x =>
x.Traveler.OfType<Traveler_Employee>().Include(e => e.Employee));


请帮我?

最佳答案

您使用了错误的类型。

public partial class Travel_RequestEmployee
{
 public virtual Traveler_Employee Traveler { get; set; }
}


注意切换到Traveler_Employee。旅行者是基础阶级。

09-06 03:34