预先加载在NHibernate的一棵树 [英] Eager loading a tree in NHibernate

查看:203
本文介绍了预先加载在NHibernate的一棵树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题试图加载一棵树,这是我的情况,我有自己(分层式)与n级相关联的实体;问题是,我可以加载用热切或的ICriteria HQL整个树?

I have a problem trying to load a tree, this is my case, I have an entity associated with itself (Hierarchic) with n levels; the question is, Can I load eagerly the entire tree using ICriteria or HQL?

在事先的任何帮助感谢。
阿里尔

Thanks in advance for any help. Ariel

推荐答案

是的......只是设置正确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).

这个帮助?

这篇关于预先加载在NHibernate的一棵树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆