我正在尝试将日期与SQL中的datetime字段进行比较。我试试这个:
Dim entry = db.Tbl_Hydrations.Where(Function(x) x.Hyd_Create_Date.Date = _date1)
然而,我得到的错误是:
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
在线:
If entry.Any Then
答案 0 :(得分:3)
似乎LINQ to Entities不支持Date属性。您可以尝试在两个日期之间进行比较作为解决方法:
Dim nextDay As DateTime = _date1.AddDays(1)
Dim entry = db.Tbl_Hydrations.Where(Function(x) x.Hyd_Create_Date >= _date1 AndAlso x.Hyd_Create_Date < nextDay)
答案 1 :(得分:1)
不确定语法(不是vb man,但你可以使用canonical functions)
Dim entry = db.Tbl_Hydrations
.Where(Function(x) EntityFunctions.CreateDateTime
(x.Hyd_Create_Date.Year, x.Hyd_Create_Date.Month, x.Hyd_Create_Date.Day, 0, 0, 0) = _date1);