Using DbFunctions I get error: The specified type member 'Date' is not supported in LINQ to Entities

.net c# entity-framework entity-framework-6

Question

Using EF 6 when I run this code even using DbFunctions.TruncateTime

var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated.Date) == report.DateCreated.Date);
var test = touches.ToList();

I get this error:

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

Any idea how to solve this.

1
0
5/28/2014 1:22:17 PM

Accepted Answer

You can pull the date up into a variable:

var reportDate = report.DateCreated.Date;
var touches = analyticRepo.GetAll()
                          .Where(x => DbFunctions.TruncateTime(x.DateCreated) == reportDate);
var test = touches.ToList();
2
5/28/2014 1:27:27 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow