0

I want get all the records between two times:

var Check1 = db.WorkingTs
               .Where(x => DbFunctions.TruncateTime(x.WorkingTime).Value.TimeOfDay >= FTime.TimeOfDay 
                        || DbFunctions.TruncateTime(x.WorkingTime).Value.TimeOfDay <= FBtime.TimeOfDay 
                        && x.FlightsCid == Crewstuff.id)
               .FirstOrDefault();

but I get the following error:

The specified type member 'Time Of Day' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported

I also tried DbFunctions.CreateTime(), but the same error still appears.

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

Create new DateTime variable first. And then use it in youre query.

var fTime = FTime.TimeOfDay;
var bTime = FBtime.TimeOfDay;

var Check1 = db.WorkingTs.Where(x => 
DbFunctions.CreateTime(x.WorkingTime.Hour, x.WorkingTime.Minute, x.WorkingTime.Second) >= fTime  
|| DbFunctions.CreateTime(x.WorkingTime.Hour, x.WorkingTime.Minute, x.WorkingTime.Second) <= bTime 
&& x.FlightsCid == Crewstuff.id).FirstOrDefault();

Btw you can use FirstOrDefault() instead of Where()

var fTime = FTime.TimeOfDay;
var bTime = FBtime.TimeOfDay;

var Check1 = db.WorkingTs.FirstOrDefault(x => 
DbFunctions.CreateTime(x.WorkingTime.Hour, x.WorkingTime.Minute, x.WorkingTime.Second) >= fTime  
|| DbFunctions.CreateTime(x.WorkingTime.Hour, x.WorkingTime.Minute, x.WorkingTime.Second) <= bTime 
&& x.FlightsCid == Crewstuff.id);