I'm trying to populate my list with missing dates where they have no sales...
I have defined a class like this:
public class GroupedItem
{
public DateTime _Date { get; set; }
public int Sales { get; set; }
}
And now the list is populated like this:
var LineGraph = _groupedItems
.GroupBy(l => l._Date.Date)
.Select(cl => new GroupedItem
{
_Date = cl.Key,
Sales = cl.Sum(c=>c.Sales)
})
.OrderBy(x => x._Date)
.Where(t => t._Date <= DateTime.Now &&
t._Date >= DateTime.Now.Subtract(TimeSpan.FromDays(date_range)))
.ToList();
And the output that I get with this is like following:
11th December 6 sales
13th December 8 sales
18th December 12 sales
19th December 25 sales
This is rather okay, but I'd like to add the dates that are missing in between the first and last date so that I can have an output like this:
11th December 6 sales
12th December 0 sales
13th December 8 sales
14th December 0 sales
15th December 0 sales
16th December 0 sales
17th December 0 sales
18th December 12 sales
21st December 25 sales
How can I achieve this with LINQ ?