I want to return a List which contains data related to the Age Distribution (Eg. For Age 0-9 there are 10 persons, for 10-19 there are 7 persons etc)
This is my query :-
public List<ReportHelper> GetAgeDistribution(int userId)
{
var itemList = (from item in this.ObjectContext.TreeMembers
where item.UserId == userId
group (DateTime.Now - (item.Birthdate ?? DateTime.Now)).Days/365.25
by ((DateTime.Now - (item.Birthdate ?? DateTime.Now)).Days / 365.25) / 9);
List<ReportHelper> list = new List<ReportHelper>();
foreach (var item in itemList)
list.Add(new ReportHelper { Data = item.Count(), Label = item.Key + "-" + (item.Key + 9) });
return list;
}
When I run this query I get dbarithmeticexpression exception :
DbArithmeticExpression arguments must have a numeric common type.
How do I solve this error? I know Entity Framework 4 is not able to translate my expression to plain old sql. How can I hint it what I am trying to do?
Thanks in advance :)