0

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)) };
Cyrus
  • 2,261
  • 2
  • 22
  • 37
espenk
  • 575
  • 2
  • 8
  • 23
  • Don't blame the poor JSON here. :) – emerson.marini Aug 14 '14 at 12:50
  • Agree.. I removed Json tag ;) – espenk Aug 14 '14 at 12:51
  • The title is misleading, this is not about how to encapsulate meta information in a JSON Result object that can contain error-messages and success-indicators, but about your specific technical problems with linq / DbArithmeticExpressions. – ovm Aug 14 '14 at 12:54

0 Answers0