lin*_*ann 7 linq entity-framework entity-framework-4.1
我有datetime变量officeStartTime
,其日期时间值为
officeStartTime = {9/24/2013 10:00:00 AM}
我有模块CHECKINOUT
包含userid
,checktime
和其它性质.
现在我想要的是获取CHECKINOUT
其时间部分检查时间大于时间部分的条目列表officeStartTime
.
我尝试:
var checklist= con.CHECKINOUTs.Where(x => x.CHECKTIME.TimeOfDay > officeStartTime.TimeOfDay);
checklist
包含以下错误:
{"The specified type member 'TimeOfDay' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."}
.
它表示TimeOfDay
在LINQ to Entities中不支持,如果是这样,我如何在LINQ中检查日期时间的一部分.有没有其他方法可以做到这一点?请建议我做什么.
谢谢.
使用EntityFunctions.CreateTime方法:
var checklist= from c in con.CHECKINOUTs
let time = EntityFunctions.CreateTime(c.CHECKTIME.Hour,
c.CHECKTIME.Minute,
c.CHECKTIME.Second)
where time > officeStartTime.TimeOfDay
select c;
Run Code Online (Sandbox Code Playgroud)
流利的语法:
con.CHECKINOUTs.Where(c => EntityFunctions.CreateTime(c.CHECKTIME.Hour, c.CHECKTIME.Minute, c.CHECKTIME.Second) > officeStartTime.TimeOfDay)
Run Code Online (Sandbox Code Playgroud)
正如抬起头,如果你正在使用实体框架版本6.0.0.0,EntityFunctions
是过时的。
可以在下面找到相同的功能DbFunctions
。
因此,对于使用EF6的答案,它看起来像这样:
con.CHECKINOUTs.Where(c => DbFunctions.CreateTime(c.CHECKTIME.Hour, c.CHECKTIME.Minute, c.CHECKTIME.Second) > officeStartTime.TimeOfDay)
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
归档时间: |
|
查看次数: |
7070 次 |
最近记录: |