I am trying to execute a query with LINQ on ASP.NET MVC 3.
I have a model, it is called Call. This Event object has a Date property, DateTime ?. I want to get events that are between 2 TimeSpans.
My code now looks like this:
TimeSpan From = new TimeSpan(8,0,0); TimeSpan Until = new TimeSpan(22,0,0); var events = from e in db.Events where e.Date.Value.TimeOfDay >= From, e.Date.Value.TimeOfDay <= Until select e;
An exception is thrown saying that "the specified element of type" TimeOfDay "is not supported in LINQ to Entities."
I have no way to solve this problem, and I tried all day. Please help me, I'm so upset. :(
EDIT:
I forgot to write "TimeOfDay" here after e.Date.Value. Anyway, I did this in my code.
I cannot use DateTime because I need to filter events that occur between certain times of the day, despite the date of the event.
sql-server linq asp.net-mvc entity-framework timespan
Umagon
source share