且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

预先加载在NHibernate的一棵树

更新时间:2021-09-07 18:28:33

是的......只是设置正确fetchmode。

Yes... just set correct fetchmode.

我会包括例如在一分钟内。

i'll include example in a minute.

例如采取从这里 =>

IList cats = sess.CreateCriteria(typeof(Cat))
    .Add( Expression.Like("Name", "Fritz%") )
    .SetFetchMode("Mate", FetchMode.Eager)
    .SetFetchMode("Kittens", FetchMode.Eager)
    .List();

您可以指定孩子太=>

You can specify to eager load child of child too =>

.SetFetchMode("Kittens.BornOn", FetchMode.Eager)






在你使用LINQ to NHibernate的情况下,使用展开方法=>


In case you are using Linq to NHibernate, use Expand method =>

var feedItemQuery = from ad in session.Linq<FeedItem>().Expand("Ads")
                           where ad.Id == Id
                           select ad;






,我会建议使用创建的helper方法字符串从lambda表达式过去了。


And i would recommend to use helper method that creates string from passed in lambda expression.

很可能,它可能告诉标准装载整棵树。但我不知道有关我宁愿指明究竟是什么,我需要(似乎危险装载的一切)。

Quite likely that it's possible to tell Criteria to load whole tree. But i'm not aware about that and i prefer specifying what exactly i need (seems dangerous to load everything).

这个帮助?