我有一个linq查询,可以执行3组bys。我想要做的是将null和0值组合在一起。或者在特定列中将所有空值更改为0。并获得该组的计数为0。另外,我想为包含0的组分配“NA”值。
我想得到的是“HowMuchSpent”组对于空值显示为0,而“Count”将它们包含在一个组中。任何帮助都会很棒。在此先感谢
我的查询如下:
var MAList =
(
from vwBudgetPop in dbContext.vw_MonitoringAsst_Budget_PO
join clientfile in dbContext.ClientFiles on vwBudgetPop.ClientFile_ID equals clientfile.ID
group vwBudgetPop by new { clientfile.CountryID_DestinationCountry } into grouped
join clientfile2 in dbContext.ClientFiles on grouped.FirstOrDefault().ClientFile_ID equals clientfile2.ID
join country in dbContext.Countries on clientfile2.CountryID_DestinationCountry equals country.ID
select new
{
Country = clientfile2.Country2.Country1 ?? "NA",
ChoiceList = from maX in grouped
group maX by maX.Choice_ID into g2
join choice in dbContext.Choices on g2.FirstOrDefault().Choice_ID equals choice.ID
select new
{
Choice = choice.Choice123,
HmSpentList =
from gd in g2
group gd by gd.HowMuchSpent_ID into hmGroup
join hmSpent in dbContext.HowMuchSpents on hmGroup.FirstOrDefault().HowMuchSpent_ID equals hmSpent.ID into hmSpentfull
from hm in hmSpentfull.DefaultIfEmpty()
select new
{
HowMuchSpent = hmSpentfull.FirstOrDefault().HowMuchSpent1,
Count = hmGroup.Count()
}
}
}
).ToList();