【发布时间】:2019-03-27 13:22:44
【问题描述】:
我正在使用 NHibernate 的 Query 的泛型实现。
我的方法:
public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where) { return SessionNH.Query<TEntidade>().Where(where); }
在这种情况下,NHibernate 首先执行 "select * from TEntidade" 将所有信息带到内存中,然后执行 "where" 条件。这需要很多时间。
有没有更好的方法?
【问题讨论】:
-
为什么不使用实体框架,(不确定
NHibernate)但是EF 将where转换为SQL中的WHERE子句,并且不会提取内存中的所有记录来进行过滤。 -
这里的所有应用程序都使用 NHibernate。如果没有大的影响,我无法更改为 EF。
-
改用
Expression<Func<TEntidade, bool>> where试试 -
就是这样!
Expression<Func<TEntidade, bool>> where工作。谢谢!
标签: c# nhibernate orm