使用DbFunctions我得到错误:LINQ to Entities不支持指定的类型成员'Date' [英] Using DbFunctions I get error: The specified type member 'Date' is not supported in LINQ to Entities

查看:558
本文介绍了使用DbFunctions我得到错误:LINQ to Entities不支持指定的类型成员'Date'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用EF 6,即使使用 DbFunctions.TruncateTime

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();

我收到此错误:


LINQ to Entities不支持指定的类型成员'Date'。
只支持初始化器,实体成员和实体导航属性

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.

推荐答案

您可以将日期提升为变量:

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();

这篇关于使用DbFunctions我得到错误:LINQ to Entities不支持指定的类型成员'Date'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆