I have this code in my controller
public JsonResult GetStatsSickDaysByMonth()
{
var sickDays = from day in sickdayRepository.All
group day by day.StartDate.Month into g
select new { month = g.Key, days = g.Sum(day => (day.EndDate - day.StartDate).Days + 1) };
return Json(sickDays, JsonRequestBehavior.AllowGet);
}
But when I try to run this I get this error:
DbArithmeticExpression arguments must have a numeric common type. ... Exception Details: System.ArgumentException: DbArithmeticExpression arguments must have a numeric common type.
This is inside a regular asp.net mvc controller.
I know I can use a more "common" approach and add the data to a class and so on. There are just sometimes very handy to return data this way
Thank you for comments below:
I fixed this based on the comments by changing code to:
var sickDays = from day in sickdayRepository.All
group day by day.StartDate.Month into g
select new { month = g.Key, days = g.Sum(day => System.Data.Entity.DbFunctions.DiffDays(day.StartDate, day.EndDate)) };