0

Having set the following options to eager load a customer's orders:

DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith<Customer>(c => c.Orders);
db.LoadOptions = dlo;

How would I then stop this and revert back to lazy loading the orders again? Or are these LoadOptions only used for the next query?

ajbeaven
  • 9,265
  • 13
  • 76
  • 121

1 Answers1

1

These load operations only apply to the next query.

If you have a second query that doesn't have these options set then it will do lazy loading.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • Thanks heaps! Also, would `db.LoadOptions.LoadWith(c => c.Orders);` do the same as the example in the question or do you need to assign a new `DataLoadOptions` object? – ajbeaven Feb 26 '13 at 10:19
  • @ajbeaven - I'm not sure I follow. I don't think you can assign a new DataLoadOptions dialog - at least we don't do that in our code, though our code is organised so there's only one query per method. – ChrisF Feb 26 '13 at 10:22
  • I'm just wondering if there's an easier way to set up eager loading than what I've showed in the example in the question, where you have to instantiate a new `DataLoadOptions` object and assign that to the context's `LoadOptions` property. – ajbeaven Feb 26 '13 at 10:26
  • @ajbeaven - no easier way. This way tells the system what parts you want to eager load and how deep you want to go. Otherwise it would have to do everything and also where would it stop? – ChrisF Feb 26 '13 at 10:27
  • Sorry yeah, I understand that you have to specify the relationships you want to eagerly load, I just wonder if you can achieve the same using a single line: `db.LoadOptions.LoadWith(c => c.Orders);` that you can in the three lines in the question's example. – ajbeaven Feb 26 '13 at 10:29