【发布时间】:2010-01-31 03:24:50
【问题描述】:
我正在尝试使用 LINQ to Nhibernate 对我的数据库中的表进行计数。但是,我正在运行的代码是拉回表中的所有记录,而不是从表中运行 select count()。
这是我的代码-
public int GetTotalCount(Func<T, bool> where) {
IQueryable<T> queryable = this._sessionManager.GetCurrentSession().Linq<T>().Where(where).AsQueryable();
return queryable.Count();
}
我也试过-
public int GetTotalCount(Func<T, bool> where)
{
IQueryable<T> queryable = this._sessionManager.GetCurrentSession().Linq<T>();
return queryable.Count(where);
}
两者都拉回整个数据集而不是运行计数。有什么想法吗?
另外,我正在使用 NHProf 对其进行分析,因此我可以查询它正在运行的查询,即
选择 * 从表
【问题讨论】:
-
您运行的是什么版本的 Linq to NHibernate 提供程序和 NHibernate 本身?
-
Nhibernate.Linq - 版本 1.1.0.1001 Nhibernate - 版本 2.1.2.4000
标签: linq nhibernate