I have datetime variable officeStartTime
which hold datetime value as
officeStartTime = {9/24/2013 10:00:00 AM}
and I have module CHECKINOUT
which contain userid
, checktime
and other properties.
Now what I want is to get list of CHECKINOUT
entries whose time part of checktime is greater than time part of officeStartTime
.
I try:
var checklist= con.CHECKINOUTs.Where(x => x.CHECKTIME.TimeOfDay > officeStartTime.TimeOfDay);
checklist
contains the following error is shown:
{"The specified type member 'TimeOfDay' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported."}
.
It says TimeOfDay
is not supported in LINQ to Entities, if so how can I check for time part of datetime in LINQ. Is there any other way to do this? Please suggest me what to do.
Thank you.
Use
CreateTime(hour, minute, second)
from Date and Time Canonical Functions
Use EntityFunctions.CreateTime method:
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;
Fluent syntax:
con.CHECKINOUTs.Where(c => EntityFunctions.CreateTime(c.CHECKTIME.Hour, c.CHECKTIME.Minute, c.CHECKTIME.Second) > officeStartTime.TimeOfDay)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With