Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
LINQ到Nhibernate计数_Linq_Nhibernate - Fatal编程技术网

LINQ到Nhibernate计数

LINQ到Nhibernate计数,linq,nhibernate,Linq,Nhibernate,我正在尝试使用LINQ to Nhibernate获取数据库中表的计数。然而,我正在运行的代码是收回表中的所有记录,而不是从表中运行select count() 这是我的密码- public int GetTotalCount(Func<T, bool> where) { IQueryable<T> queryable = this._sessionManager.GetCurrentSession().Linq<T>().Where

我正在尝试使用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-where){
IQueryable queryable=此._sessionManager.GetCurrentSession().Linq().Where(Where).AsQueryable();
返回queryable.Count();
}
我也试过了-

    public int GetTotalCount(Func<T, bool> where)
    {
        IQueryable<T> queryable = this._sessionManager.GetCurrentSession().Linq<T>();
        return queryable.Count(where);
    }
public int GetTotalCount(Func-where)
{
IQueryable queryable=这个;
返回可查询的计数(其中);
}
两者都会拉回整个数据集,而不是运行计数。有什么想法吗

此外,我正在使用NHProf对其进行评测,以便可以查看它正在运行的查询,这是

挑选*
从表

中,您的
,其中
参数需要是一个
表达式
;否则,您将加载内存中的所有内容,并使用LINQ访问对象

简言之:

public int GetTotalCount(Expression<Func<T, bool>> where)
{
    return _sessionManager
        .GetCurrentSession()
        .Linq<T>()
        .Where(where);
        .Count();
}
public int GetTotalCount(表达式where)
{
返回会话管理器
.GetCurrentSession()
林奇议员()
.何处;
.Count();
}

您正在运行哪个版本的Linq to NHibernate提供程序和NHibernate本身?NHibernate.Linq-version 1.1.0.1001 NHibernate-version 2.1.2.4000几天前就解决了这个问题。这就是问题所在。答案很好!我不知道为什么我的where子句没有被翻译成查询。那么该如何使用它呢?