views:

38

answers:

1

Hi, 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 database 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

+2  A: 

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.

Diego Mijelshon