Consider the these two LINQ2SQL data retrieval methods. The first creates a 'proper' SQL statement that filters the data, but requires passing the data context into the method.
The second has a nicer syntax but loads the entire list of that accounts projects, then does in memory filtering.
Is there any way to preserve the syntax of the second method but with the performance advantage of the first?
public partial class Account
{
public IQueryable<Project> GetProjectsByYear(LinqDataContext context, int year)
{
return context.Projects.Where(p => p.AccountID==this.AccountID && p.Year==year).OrderBy(p => p.ProjectNo)
}
public IQueryable<Project> GetProjectsByYear(int year)
{
return this.Projects.Where(p => p.Year==year).OrderBy(p => p.ProjectNo).AsQueryable()
}
}