I am using a generics implementation of Query from NHibernate.
My method:
public IEnumerable<TEntidade> ObterEntidadesPor(Func<TEntidade, bool> where) { return SessionNH.Query<TEntidade>().Where(where); }
In this case, the NHibernate first do the "select * from TEntidade" bring all information to memory after all this, he implement the "where" conditional. This are taking to much time.
Is there a better way to do it?
The problem was solved with Expression<func>
.
public IEnumerable<TEntidade> ObterEntidadesPor(Expression<Func<TEntidade, bool>> where)
{
return SessionNH.Query<TEntidade>().Where(where);
}
While searching for answer, a colleague told me that the Func
executes the query before build an expression. To build an expression before executing the query, we have to use Expression
.
This is also mentioned by @RomanArtiukhin in comments on question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.