I have the following LINQ to Entities query that has many subqueries to get some aggregated data:
var systems = from s in db.Systems
orderby s.Name
select new SystemSummary
{
Id = s.Id,
Code = s.Code,
Name = s.Name,
LastException = (
from a in s.Applications
from e in a.Summaries
select e.CreationDate
).Max(),
TodaysExceptions = (
from a in s.Applications
from e in a.Summaries
where e.CreationDate >= today && e.CreationDate < tomorrow
select e
).Count(),
};
I shortened the request to include only 2 subqueries, but there can be about 10-15. Is there a way so that I can reorganize the request to clear the code? I am not looking for performance improvements. I want to just clear the code, perhaps by placing the subqueries in separate methods , still making sure that this is one database call. Is it possible?
source
share