NHibernate 中是否可以急切加载两个一对多关系?
给定如下所示的对象层次结构:
class Category
{
List<SubCategory> SubCategories;
}
class SubCategory
{
List<Product> Products;
}
class Product
{
}
是否可以使用 NHibernate 预先加载整个层次结构? 我想执行一个查询来加载所有类别以及急切加载的子类别和产品。
Given an object hierarchy such as the following:
class Category
{
List<SubCategory> SubCategories;
}
class SubCategory
{
List<Product> Products;
}
class Product
{
}
Is it possible to eager load the whole hierarchy using NHibernate? I would like to execute one query to load all categories with subcategories and products eager loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,有可能......但是,您不认为这会对性能产生一些影响吗? 您可能会检索大量数据。
为此,您必须使用 ICriteria 的“SetFetchMode”方法来检索实例。
像这样的东西:
或者,也许通过使用 CreateAlias:
也许你必须根据你的情况/你想要的来尝试一下可能的 JoinTypes。
Yes , it is possible ... However, don't you think that this will have some performance implications ? It is possible that you retrieve a huge amount of data.
in order to do it, you'll have to use the 'SetFetchMode' method of the ICriteria that you'll use to retrieve the instances.
Something like this:
Or, maybe by using CreateAlias:
perhaps you'll have to play a bit with the possible JoinTypes, depending on your situation / what you want.