2011-05-15 35 views
4

使用实体框架,您可以执行类似的操作来为查询加载多个引用的对象。具有多个引用的实体框架LoadProperty

var Customer = context.Customers.Include(x=>x.Orders.Select(y=>y.Items)); 

看起来好像我可以用LoadProperty方法做同样的事情。当我已经有一个对象,我需要加载一些参考数据,我使用LoadProperty。

context.LoadProperty(Customer, x=>x.Orders); 

这是行得通的。但是,这将引发错误..

context.LoadProperty(Customer, x=>x.Orders.Select(y=>y.Items)); 

所以做到这一点...

context.LoadProperty(Customer.Orders, x=>x.Items); 

这是两种情况例外...

为 LoadProperty的选择表达必须是属性的MemberAccess 。

回答

1

LoadProperty不允许。您可以尝试使用another question中描述的方法。

1

我有同样的问题,最终通过实体循环和加载它们一个接一个:

EFContext.LoadProperty(primingRunSelector, f => f.PrimingRun); 
EFContext.LoadProperty(primingRunSelector.PrimingRun, f => f.PrimingFillbagAssignedTos); 
foreach (var primingFillbagAssignedTo in primingRunSelector.PrimingRun.PrimingFillbagAssignedTos) EFContext.LoadProperty(primingFillbagAssignedTo, f => f.PrimingFillbag);