开发者

Eager loading with HQL

Is it possible to do eager loading with HQL without touching mappings? The "left join fetch" expression is completely ignored by nHibernate.

var query = Session.CreateQuery("from o in Member left join fetch o.Photos");
query.List<Member>();

The generated SQL is

SELECT this_.Id as Id7_1_, this_.Name as Name7_1_, this_.AltNames as AltNames7_1_,
this_.Tags as Tags7_1_, this_.Loved as L开发者_开发问答oved7_1_, profile2_.id as id6_0_,
profile2_.Website as Website6_0_, profile2_.Email as Email6_0_, 
profile2_.Shop as Shop6_0_ 
FROM Member this_ 
left outer join member_profile profile2_ on this_.Id=profile2_.id 
limit 10;

And then 10 statements grabbing the photos. MemberProfile is mapped as OneToOne.


You could use the fetch keyword:

from Cat as cat inner join fetch cat.Mate

This will eagerly load the Mate association.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜