Entity Framework LoadProperty with Multiple Links

With an entity framework, you can do something similar to load objects for multiple request links.

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

It doesn't seem like I can do the same with the LoadProperty method. When I already have an object and I need to load some reference data, I use LoadProperty.

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

It works. But it causes an error.

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

And that too ...

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

This is an exception for both cases ...

The selector expression for LoadProperty must be MemberAccess for the property.

+4
source share
2 answers

No LoadProperty this. You can try to use the approach described in another question .

+1
source

I had the same problem and ended the loop through entities and loaded them one at a time:

 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); 
+1
source

All Articles