我正在对 MySql 使用 NHIbernate,当我使用以下语句时,NHibernate Profiler 向我显示传递给 MySql 的查询基本上是 SELECT * FROM tablename with NO WHERE 子句。直到检索到所有数据后,才会应用 LINQ 表达式。从性能的角度来看,这显然是 Not Acceptable 。我做错了什么?
Session.Linq<T>().Where(expression).AsQueryable()
谢谢!
[更新] 正如@GertArnold 所猜测的那样,在此之前的调用是:
public IQueryable<Student> FindByExpression(Func<Student, bool> expression)
表达式是:
_studentRepository.FindByExpression(t =>
(t.Teacher.Id == dto.TeacherId) &&
(t.Id != dto.Id) &&
(
(t.ExternalId != null && student.ExternalId != null
)
最佳答案
你应该使用 Expression<Func<T, bool>>
而不是 Func<T, bool>
.
关于mysql - NHibernate.ISession.Linq<T>.Where(expression) 检索整个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6950422/