下面是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();
您可以为上下文设置DataLoadOptions。大致如下:
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Role>(c => c.EmployeeId);
context.LoadOptions = options;
以下是一篇可能有所帮助的文章:http://blogs.msdn.com/b/adonet/archive/2008/10/07/migrating-from-linq-to-sql-to-entity-framework-eager-loading.aspx