I need to show the user a presentation , the information for display is in different tables.
For simplicity, I receive the data in several requests, then I glue all this data using left joints .
linq query looks like this:
var operations = _context.Set<Operation>() .Include(x=>x.Product) .ToList(); var timeWorks = _context.Set<OperationItem>() .Where() .ToList(); var attachments = _context.Set<OperationItem>() .Where() .ToList(); var result = operations .GroupJoin(attachments, o=>o.Id, i=>i.OperationId, (l,r)=> new {Operation = l, Attachment = r}) .SelectMany(x=>x.Attachment.DefaultIfEmpty(), (l,r)=>new {Operation = l.Operation, Attachment = r}) .GroupJoin(timeWorks, o=>o.Operation.OperationId, i=>i.OperationId, (l,r)=> new {Operation = l.Operation, Attachment = l.Attaqchment, TimeWork = r.Sum(_=>_.TimeWork)}) .Select(x=> new OperationList { //Собираем окончательное представление }) .ToList(); Everything works as it should, but I don’t like the fact that for each left connection I have to pass the result of the previous connection:
new {Operation = l.Operation, Attachment = l.Attaqchment, TimeWork = r.Sum(_=>_.TimeWork)} Tell me, can I do something wrong and can it be made easier?