views:

115

answers:

1

I have a simple one to many association in my model. The parent class has a collection of children. In the mapping files, the association is a one to many, eager-loaded, using fetchmode.join. This works fine, but how can I write a criteria query but NOT trigger the loading of the child collection? In other words, I want to query the parent and not have it generate the join in the resulting sql. I tried setting the fetch mode to lazy, but in that case Nhibernate generates two separate queries. I don't want the table for child queried at all.

A: 

You can use SetFetchMode in the Criteria API but there is no FetchMode that will turn off eager loading. If you are joining on a primary/foreign key relationship and the collection size is reasonable then I wouldn't worry about it. If that's not the case, then you will probably need to switch to lazy loading the collection.

Jamie Ide