Hi,
I have a LINQ query which is fetching a list of nested objects.
from c in ClientsRepository.LoadAll()
orderby c.Name
select new ComboBoxOptionGroup
{
Text = c.Name,
Options = from p in c.Projects
orderby p.Name
select new ComboBoxOption
{
Text = p.Name,
Value = p.ID.ToString()
}
}
Unfortunately this LINQ query results in num(clients)+1 SQL queries. Is there any elegant way of rewriting this so that it only results in one SQL query?
My idea would be to fetch all projects ordered by clients and to do the rest of the work in two nested foreach loops, but that seems to defy the elegance that was intended when LINQ was designed. Are there any better options?