I'm measuring database calls on a slow site using NHibernate profiler, and have noticed immediately that the following is causing a Select N+1 issue.
I've never used NHibernate so was hoping someone could help me out?
public virtual IQueryable<Employee> Employees()
{
return Session.Query<Employee>();
}
public IList<Employee> GetEmployeesByClientId(int clientId)
{
return Employees()
.Where(e => e.ClientId == clientId && e.Deleted == false)
.ToList();
}
At the point of calling ToList() a select statement is ran for every related record of EmployeeDetail
, and I'm not sure why.
public virtual EmployeeDetail EmployeeDetail { get; set; }