0
您好,我有一個linq查詢下方該組購買月份和該月的總和。查詢有效,但是當某個月沒有購買時,我希望它在該月份返回0。在那一刻它只是蹦蹦跳跳那個月。例如,如果只有半年LINQ查詢只返回6條,我想返回購買12中,其中6將等於0LINQ sum和groupby並返回空記錄?
var purchaseData = (from p in db.Purchases
where p.UserId == WebSecurity.CurrentUserId
group p by new {p.DateBought.Value.Month} into g
select new {g.Key.Month, Sum = g.Sum(p => p.Price)}).ToArray();
string[] myArray = new string[12];
for (int i = 0; i < purchaseData.Length; i++)
{
myArray[i] = purchaseData[i].Sum.ToString();
}
我將如何做到這一點?
感謝