Nhibernate Criteria Ignore Child Collection

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.


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.

链接地址: http://www.djcxy.com/p/36990.html

上一篇: jpa将孩子从收藏中删除

下一篇: Nhibernate标准忽略子集合