Using DbFunctions I get error: The specified type

2019-09-06 14:56发布

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条回答
再贱就再见
2楼-- · 2019-09-06 15:27

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();
查看更多
登录 后发表回答