nHibernate集合计数 [英] nHibernate Collection Count

查看:116
本文介绍了nHibernate集合计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模型,我已经创建和映射与nHibernate。
使用延迟加载,所以我不需要在开始时为经销商获取车辆。

 公共类经销商
{
public virtual string Name {get; set;}
public virtual IList< Vehicles>车辆{get; set;}
}

现在让我们假设经销商有数千辆车。



如果我执行 Dealer.Vehicles.Count ,那么NH将选择并拉取所有数据。 >

什么是最简单的计数方法?有没有什么方法,我可以得到一个计数与在经销商类中声明一个新的属性dealerCount?



还有一个功能在Hibernate,我相信将是实现在一个更新的版本的NH称为额外懒加载。这将解决这个问题?

解决方案

额外延迟加载将发出sql而不是填充集合某些操作,如 Count 包含。在流畅的映射中它用作:

  HasMany(x => x.CollectionProperty).ExtraLazyLoad(); 

或HBM

 < one-to-many lazy =extra... 

只有有用的,如果你有大的集合,需要特殊的行为。


I have the following model which I have created and mapped with nHibernate. Using lazy loading so I don't need to get the Vehicles for the Dealer at the start.

Public class Dealer
{
public virtual string Name { get;set;}
public virtual IList<Vehicles> Vehicles { get;set;}
}

Now let's assume the Dealer has thousands of vehicles.

If I do Dealer.Vehicles.Count then NH will select and pull all the data.

What is the best way to simply get a count? Is there any way in which I can get a count with out declaring A new property dealerCount within the Dealer Class?

Also there is a feature in Hibernate which I believe will be implemented in a newer version of NH called Extra Lazy Loading. Would this solve the problem?

解决方案

extra lazy loading would issue sql instead of populating the collection for certain operations such as Count or Contains. In fluent mappings its used as:

HasMany(x => x.CollectionProperty).ExtraLazyLoad();

or HBM

<one-to-many lazy="extra" ...

It's only usefull if you have large collections and need the special behavior.

这篇关于nHibernate集合计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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