实体框架和LINQ查询日期 [英] Entity Framework and LINQ querying dates

查看:80
本文介绍了实体框架和LINQ查询日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用日期查询视图并收到错误



附加信息:指定的类型成员'日期'不受支持LINQ to Entities。仅支持初始值设定项,实体成员和实体导航属性。



在线查看之后建议使用dbfunctions.truncatetime但是我是仍然遇到同样的错误,我使用的代码是:



I'm trying to query a view using a date and am getting the error

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

after looking online it was suggested to use the dbfunctions.truncatetime but alas I am still experience the same error, the code I am using is:

Dim items As List(Of vwReceptionKeys) = db.vwReceptionKeys.Where(Function(x) DbFunctions.TruncateTime(x.Arrival_Date) = Now.Date).Take(25).ToList()





有人可以指点我正确的方向吗?



谢谢



Could someone please point me in the correct direction?

Thanks

推荐答案

通过将日期发布到查询中来解决:



Solved by storing date post putting it into the query:

Dim today As Date = Now.Date

Dim items As List(Of vwReceptionKeys) = db.vwReceptionKeys.Where(Function(x) x.Arrival_Date > today).Take(25).ToList()


这篇关于实体框架和LINQ查询日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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