问题描述:

i want to get the data in my table date wise with total

Here is my code what am trying to do

var result = from a in db.table

group a by a.date.Date into g

select new { date = g.Key, distance = g.Sum(a => a.distance) };

return View(result.ToList());

If am using without Date part then am getting every data in a day.

But by using this linq am getting error "The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties".

网友答案:

Try this, as Date is class and is not supported by entity framework. you need to use truncate time function which converts datetime to date.

var result = from a in db.table
                      group a by EntityFunctions.TruncateTime(a.date) into g
                      select new { date = g.Key, distance = g.Sum(a => a.distance) };
 return View(result.ToList());

Entity Functions

相关阅读:
Top