C# 按Linq分组时更改原始表值
我有一个linq查询,它执行3个group BY。我要做的是将null值和0值分组在一起。或者将特定列中的所有空值更改为0。并获取具有0的组的计数。我还想给包含0的组分配一个“NA”值 我想要得到的是“HowMuchSpent”组对于空值显示为0,以及“Count”将它们包含在一个组中。任何帮助都会很好。提前谢谢 我的问题如下:C# 按Linq分组时更改原始表值,c#,linq,C#,Linq,我有一个linq查询,它执行3个group BY。我要做的是将null值和0值分组在一起。或者将特定列中的所有空值更改为0。并获取具有0的组的计数。我还想给包含0的组分配一个“NA”值 我想要得到的是“HowMuchSpent”组对于空值显示为0,以及“Count”将它们包含在一个组中。任何帮助都会很好。提前谢谢 我的问题如下: var MAList = ( from vwBudgetPop in dbContext.vw_MonitoringAsst_Budget_P
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();
错误是什么?或者您得到的输出是什么?我得到的输出分组如下-选项1:。我想要得到的是-Choice 1: