A controller should return data that is used as source for a D3.js line chart. In the controller, I've got a list of objects and I'm only interested in the property "Begin" and count(Begin). Begin is a datetime and what I want is to group all Objects where "Begin" is on the same day, and then count the number for each day.
I try to select this information and return it this way:
var results = from a in db.Questionaires
group a by a.Begin.Date into g
select new { Date = g.Key, Count = g.Count() };
return Json( results, JsonRequestBehavior.AllowGet);
Unfortunatly, I'm getting an error because the group by clause seems to be wrong ("The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.").
How to select the information the right way? If anybody has some examples on D3.js and MVC I would appreciate that.
You should try this
var results = from a in db.Questionaires
group a by new { y = a.Begin.Year, m = a.Begin.Month, d = a.Begin.Day}
into g
select new { Day = g.Key.d, Year = g.Key.y,
Month = g.Key.m, Count = g.Count(),
Date = g.Select(d=>d.Begin).FirstOrDefault() };