1

I have an object of SomeType with two collections in it, A and B, and lets say some boolean property C to help with the example.

I found out already the hard way that I cannot do:

IQueryable<SomeType> query = getIQueryableSomehow();
List<SomeType> = query.Where(x => x.C).Fetch(x => x.A).Fetch(x => x.B).ToList();

Then, I get duplicate B results for however many objects there are in A. Cartesian product..

I can't seem to find any information on how to eager fetch more than one collection. Does anyone know how to do it all in one query? Is it currently impossible?

Thanks!

Isaac Bolinger
  • 7,328
  • 11
  • 52
  • 90

1 Answers1

2

Yes you can do this by using Futures. Take a look here:

Eagerly fetch multiple collection properties (using QueryOver/Linq)?

Or here:
NHibernate lazy loading nested collections with futures to avoid N+1 problem

Community
  • 1
  • 1
Cole W
  • 15,123
  • 6
  • 51
  • 85