下面是linq查询,其中我想在选择员工时检索Team对象。如何通过linq join实现预先加载?如果没有linq join语句,我可以检索Team对象(急切加载)。
Employee x = (from emp in context.Employees.Include("Team")
join role in context.Roles on
emp.EmployeeId equals role.EmployeeId
select emp ).Single();
答案 0 :(得分:2)
您可以为上下文设置DataLoadOptions。这些方面的东西:
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Role>(c => c.EmployeeId);
context.LoadOptions = options;