开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜