I have a linq which groups prices by month works perfectly except I can’t see the months which doesn’t have data. what I am expecting If a month doesn’t have data price should be 0.
List<decimal> osman1 = osman.GroupBy(i => new
{
Field1 = i.Field<DateTime>("CreateDate").Month
})
.Select(group => group.Sum(i => Convert.ToDecimal(i["Price"])))
.ToList();
result osman1 is
{221,103,352}
what I need is
{0,0,0,0,0,0,0,221,0,103,352,0}
The simplest way is probably to do a group join:
(I’ve used
Field<decimal>rather thanConvert.ToDecimalas I think it’s usually cleaner; change it if you need to, of course.)