Comparing datetime 24hs to AM/PM format with Entity Framework
I am new with Entity Framework. I am having problems comparing datetime values since in my SQL Server database the datetime values are stored as 24hs format and the application is taking the time format as A.M./P.M. format. I tried to parse the fields but I get the error message:
The sp开发者_开发知识库ecified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.>
Here is what I tried: (this returns true or false if there are any record found)
<pre><code>
return !(DB.Eventos.Where(
x =>
(x.Fecha_inicio_evento.Date >= eventos.Fecha_inicio_evento.Date
&&
x.Fecha_inicio_evento.TimeOfDay >= eventos.Fecha_inicio_evento.TimeOfDay
&&
x.Fecha_inicio_evento.Date <= eventos.Fecha_fin_evento.Date
&&
x.Fecha_inicio_evento.TimeOfDay <= eventos.Fecha_fin_evento.TimeOfDay)
||
(x.Fecha_fin_evento.Date >= eventos.Fecha_inicio_evento.Date
&&
x.Fecha_fin_evento.TimeOfDay >= eventos.Fecha_fin_evento.TimeOfDay
&&
x.Fecha_fin_evento.Date <= eventos.Fecha_fin_evento.Date
&&
x.Fecha_fin_evento.TimeOfDay <= eventos.Fecha_fin_evento.TimeOfDay
)).Any());
</code></pre>
Do you know any way to perform that?
Database
or .Net
does not store date in format. Format is only description for methods like ToString
how to do the task. So comparison can be done standard way with operator. Error you're getting is connected with translation Linq
query to sql
by entity framework
, simply Date
isn't upported.
If by splitting comparison to 2 parts you wanted to compare the dates its not correct. Id .Date
is higher comparison of the .TimeofDay
shouldn't change result but it does. Chech result with Fecha_inicio_evento
= 2011-01-02 01:01:01 and Fecha_inicio_evento
= 2011-01-01 02:01:01
精彩评论