Linq for NHibernate mode and boot fetch

Is there a way to set fetchmode for more than one object using linq for nhibernate. There seems to be an extension method that only allows me to set up one object. However, I need to set it for several objects. Is it possible? Thanks

+44
linq fetch nhibernate eager
May 6, '09 at 21:13
source share
4 answers

just use it more than once.

IList<Entity> GetDataFromDatabase() { var query = session.Linq<Entity>(); query.Expand("Property1"); query.Expand("Property2"); return query.ToList(); } 
+18
May 6 '09 at 23:57
source share

The new Linq provider does this a little differently:

 var customers = session.Query<Customer>().Fetch(c => c.Orders).ToList(); 

More details here: http://mikehadlow.blogspot.com/2010/08/nhibernate-linq-eager-fetching.html

+102
Aug 06 '10 at 11:22
source share

As far as I can see, this is not equivalent: SetFetchMode removes the tree of objects, and the Expand method retrieves the Cartesian product.

+8
Sep 20 '09 at 20:23
source share

In response to @Mike Hadlow answer, the choice of the next level (grandchildren) you need to do:

var customers = session.Query<Customer>() .FetchMany(c => c.Orders) .ThenFetchMany(o => o.OrderLines).ToList();

0
Dec 15 '16 at 13:15
source share



All Articles