Using this code in Entity Framework I receive the following error.
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
My code:
DateTime startdate = DateTime.Now.Date.AddDays(-7);
var result = (from c in db.orders
where DbFunctions.TruncateTime(c.creationtime.Value) >= startdate
group c by new
{
date = DbFunctions.TruncateTime(c.creationtime).Value.Date,
}
into g
select new
{
date = g.Key.date,
Total = g.Count(),
attend = g.Where(f => f.canceled != true && f.attindance != false).Count(),
notattend = g.Where(f => f.canceled != true && f.attindance == false).Count(),
canceled = g.Where(f => f.canceled == true).Count(),
other = g.Where(f => f.canceled == null && f.attindance == null).Count()
}).OrderByDescending(m => m.date).ToList();
Source Error:
Line 156: {
Line 157: DateTime startdate =DateTime.Now.Date.AddDays(-7);
**Line 158: var result = (from c in db.orders**
Line 159: where DbFunctions.TruncateTime(c.creationtime.Value) >= startdate
Line 160:
Source File: Controllers\HomeController.cs Line: 158