I found this post and I need something similar
I need to group by month and year, but at the same time I need a property of the main element, which I can not access
var departments = stops
.SelectMany(x => new[] { x.InitDate.Month, x.InitDate.Year }
.Where(dt => dt != null).Select(dt => x.InitDate))
.GroupBy(dt => new { dt.Month, dt.Year })
.OrderBy(g => g.Key.Month)
.ThenBy(g => g.Key.Year)
.Select(g => new
{
Key = g.Key.Month,
Año = g.Key.Year,
Duration = 0,
Count = g.Count()
});
I would need access to "stops.Duration" but if i do this: .SelectMany(x => new[] { x.InitDate.Month, x.InitDate.Year, x.Duration }
it does not group me by month-year
Can anybody help me?
Sorry for my english and thank you very much