The use of the .ToList()
function in the construction of the variable result
, leads to execute the query. Considering result as a variable of type IQueryable<TimeEntryReportModel>
instead of a list, the request will be executed later (when calling .ToList()
in the controller method).
So, you can write:
IQueryable<TimeEntryReportModel> result = (
...
).Distinct().OrderBy(n => n.DisplayName);
And later (in same or other function), specify the query by adding the where clause:
...
var specifiedResult = result.Where(e => e.UserId == userId).ToList();
Deferred execution is, in my opinion, one of the main interests of LINQ.