I have the following issue: I want to display Tickets from a helpdesk system in a neat overview. I also want to display summaries of the data, like groupings by priority and category. On top of that, the same data must be turned into a .pdf document.
I retrieve the data in several steps. Step one is raw data which is the base for the .pdf, the summaries and the actual overview. That way, I ensure they take the same data. Upon creating the .pdf I directly read from the data. The summaries are made by flattening the data. The overview is created by taking a page of 25 records from the data and putting the fields in a grid.
The problem is
IQueryable<RelationHoursTicketItem> HoursByTicket =
from Ticket t in allTickets
let hours = t.Bezoekrapport.Urens.
Where(h =>
(dateFrom == null || h.Datum >= dateFrom)
&& (dateTo == null || h.Datum <= dateTo)
&& h.Uren1 > 0)
select new RelationHoursTicketItem
{
Date = t.DatumCreatie,
DateSolved = new DateTime(2012, 11, 11),
Ticket = t,
Relatie = t.Relatie,
TicketNr = t.Id,
TicketName = t.Titel,
TicketCategorie = t.TicketCategorie,
TicketPriority = t.TicketPrioriteit,
TicketRemark = t.TicketOpmerkings.SingleOrDefault(tr => tr.IsOplossing)
};
The problem is in TicketRemark. As soon as I execute the data, I get tens of subqueries since the TicketOpmerkings - Dutch for TicketRemarks - are retrieved one by one. The original intention was to create an IQueryable which would serve as base for all other queries. I have gone through great lengths to achieve this, creating custom expressions to calculate certain fields which I cut from this example.
What is the best possible approach? Writing expressions for all those links like t.TicketOpmerkingen? It would remove some of the best functionality of LINQ. Solutions I saw so far include manually creating Expressions, but then I can just as well forsake this approach and make several queries, each for its specific purpose. Then I forsake the neat 'layered' approach of LINQ and IQueryable.
Anybody some experience with this?