开发者

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>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜