【发布时间】:2009-06-03 11:59:24
【问题描述】:
假设以下层次结构:
class Department { EntityCollection<Employee> Employees; }
class Employee { string Name; }
class RemoteEmployee : Employee { Country Location; EntityReference<Country> CountryReference; }
因此,部门包含员工列表。员工类型有一个层次结构,一些类型引用其他实体。 假设我们需要向部门加载其员工。好的,没问题:
dataContext.Departments.Include("Employees")
这将返回具体的员工类型(即 RemoteEmployee 用于远程)。 现在我们需要使用远程员工加载 Location。
dataContext.Departments.Include("Employees").Include("Employees.Location") - Error: no such property in Employee
dataContext.Departments.Include("Employees").Include("RemoteEmployees.Location") - Error: no such property in Department
我应该在 Include 中指定什么来使用 RemoteEmployee 加载 Location?
【问题讨论】:
-
ALex 的解决方案有什么问题。你为什么不接受它,这样他就可以从中获得奖励?
标签: entity-framework inheritance include