Jim*_*mbo 14 c# datetime entity-framework
我需要从我的数据库中返回一个项目列表,该列表在项目提供的日期的预定时间到期.我的错误代码如下:
return All().Where(o => new DateTime(o.expiry_date.Year, o.expiry_date.Month, o.expiry_date.Day, 17, 30, 0) >= DateTime.Now)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
LINQ to Entities中仅支持无参数构造函数和初始值设定项
有谁知道我怎么解决这个问题?
Eup*_*ric 30
请改用EntityFunctions.也许CreateDateTime方法.
所以也许是这样的:
return All().Where(o => EntityFunctions.CreateDateTime(o.expiry_date.Year, o.expiry_date.Month, o.expiry_date.Day, 17, 30, 0) >= DateTime.Now)
Run Code Online (Sandbox Code Playgroud)
更新:
使用EF6时,请改用DbFunctions.
您可以使用:
var result = await db.Articles
.Where(TruncateTime(x.DateCreated) >= EntityFunctions.TruncateTime(DateTime.Now))
.ToListAsync();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30789 次 |
| 最近记录: |