Combining 2 Linq queries into 1

Posted by Mike Fielden on Stack Overflow See other posts from Stack Overflow or by Mike Fielden
Published on 2010-05-10T20:30:05Z Indexed on 2010/05/10 20:34 UTC
Read the original article Hit count: 243

Filed under:
|

Given the following information, how can I combine these 2 linq queries into 1. Having a bit of trouble with the join statement.

'projectDetails' is just a list of ProjectDetails
ProjectDetails (1 to many) PCardAuthorizations
ProjectDetails (1 to many) ExpenditureDetails

Notice I am grouping by the same information and selecting the same type of information

var pCardAccount =  from c in PCardAuthorizations
                    where projectDetails.Contains(c.ProjectDetail)
                        && c.RequestStatusId == 2 
                    group c by new { c.ProjectDetail, c.ProgramFund } into g

                    select new { Key = g.Key, Sum = g.Sum(x => x.Amount) };



var expenditures =  from d in ExpenditureDetails
                    where projectDetails.Contains(d.ProjectDetails)
                        && d.Expenditures.ExpenditureTypeEnum == 0
                    group d by new { d.ProjectDetails, d.ProgramFunds } into g
                    select new {
                        Key = g.Key,
                        Sum = g.Sum(y => y.ExpenditureAmounts.FirstOrDefault(a => a.IsCurrent && !a.RequiresAudit).CommittedMonthlyRecords.ProjectedEac)
                    };

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-sql