NHibernate.ISession.Linq<T>.Where(expression) retrieves whole table
I am using NHIbernate against MySql, and when I use the following statement, NHibernate Profiler shows me that the query passed to MySql is basically SELECT * FROM tablename with NO WHERE clause. The LINQ expression isn't applied until after all the data are retrieved. This is obviously not acceptable from a performance standpoint. What am I doing wrong?
Session.Linq<T>().Where(expression).AsQueryable()
Thanks!
[UPDATE] As @GertArnold guessed, the call preceding this was:
public IQueryable<Student>开发者_JAVA百科 FindByExpression(Func<Student, bool> expression)
The expression was:
_studentRepository.FindByExpression(t =>
(t.Teacher.Id == dto.TeacherId) &&
(t.Id != dto.Id) &&
(
(t.ExternalId != null && student.ExternalId != null
)
You should use an Expression<Func<T, bool>>
instead of Func<T, bool>
.
精彩评论