For some reason, when using two sums on a group by, i run into the error "invalid column name 'id'. When i only do one sum, it works as expected.
The following fails and throws the error:
from pd in PrDetails.Where(_pd => _pd.PrId == 46)
group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs }
into g
select new
{
g.Key.ProgramFund,
g.Key.CostCenter,
g.Key.Wbs,
CommittedTotal = g.Sum(_pd => _pd.PrDetailPrAmounts.Sum(_pa => _pa.CommittedAmount)),
OverheadTotal = g.Sum(_pd => _pd.PrDetailPrAmounts.Sum(_pa => _pa.OverheadAmount))
}
However, the following does work fine:
from pd in PrDetails.Where(_pd => _pd.PrId == 46)
group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs }
into g
select new
{
g.Key.ProgramFund,
g.Key.CostCenter,
g.Key.Wbs,
CommittedTotal = g.Sum(_pd => _pd.PrDetailPrAmounts.Sum(_pa => _pa.CommittedAmount))
}
And also, when I get the overhead total, instead of the committed total, it works great:
from pd in PrDetails.Where(_pd => _pd.PrId == 46)
group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs }
into g
select new
{
g.Key.ProgramFund,
g.Key.CostCenter,
g.Key.Wbs,
OverheadTotal = g.Sum(_pd => _pd.PrDetailPrAmounts.Sum(_pa => _pa.OverheadAmount))
}
Why can't i get the committed total and overhead total at the same time?
I have our basic table structure below:
PrDetails
Id (int)
PrId (int)
ProgramFund (linq class)
ProjectDetail (linq class)
ProjectDetails
Id (int)
CostCenter (linq class)
Wbs (linq class)
PrAmounts
Id (int)
PrDetailId (int)
CommittedAmount (decimal)
OverheadAmount (decimal)