Using NHibernate.Linq and getting 2 queries for a simple select, why?
so here's the code with irrelevant bits left out:
public IEnumerable<T> GetByQuery(Expression<Func<T, bool>> filter
{
try
{
return Session.Linq<T>().Where(filter);
}
catch(Exception ex)
{
// custom exception handling here
}
finally
{
CloseSession();
}
return null;
}
and an example of it being called looks like this:
IEnumerabl<ClientReport> clientReports =
clientReportRepository.GetByQuery(item => item.ClientId = id);
So as you can see, nothing fancy and being called in this way, we're hitting one table in the datab开发者_高级运维ase with no relationships to any other tables. But when I have show_sql = true in the configuration, It's displaying 2 of the same query. Any ideas? Thanks
clientReports will probably execute the query every time you enumerate it (or get the Count(), for example).
To avoid that, use .ToList() in the assignment.
加载中,请稍侯......
精彩评论