4

With entity framework you can do something like this to load objects for multiple references with a query.

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

It doesn't seem like I can do the same thing 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);

That works. But this throws an error..

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

And so does this...

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

This is the exception for both cases...

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

BZink
  • 7,687
  • 10
  • 37
  • 55

2 Answers2

1

I had the same problem and ended up looping through the entities and loading them one by one:

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);
user500099
  • 964
  • 9
  • 9
1

No LoadProperty doesn't allow that. You can try to use approach described in another question.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670