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 specified 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?
Databaseor.Netdoes not store date in format. Format is only description for methods likeToStringhow to do the task. So comparison can be done standard way with operator. Error you’re getting is connected with translationLinqquery tosqlbyentity framework, simplyDateisn’t upported.If by splitting comparison to 2 parts you wanted to compare the dates its not correct. Id
.Dateis higher comparison of the.TimeofDayshouldn’t change result but it does. Chech result withFecha_inicio_evento= 2011-01-02 01:01:01 andFecha_inicio_evento= 2011-01-01 02:01:01