Question:
I’m trying to retrieve records from a database in Azure and for the checks I run T-SQL queries directly and then pass them to LINQ against the EF Core context, but I’m running into this problem.
FechaOrientativa
greater than or equal to Today, the Estudiar
field is equal to ‘pt’, I get 2,296 records.Now in Angular, I do http.Get to my Web API where I execute the following:
Any idea, please?
Thanks.
Answer:
Compare both SQL query and EF LINQ query, the difference is:SQL –
CAST( GETDATE() AS Date )
returns Today Date without time.EF LINQ –
DateTime.Now
returns current Date Time.Hence the queried result will be different
(Example: Only queried records with the date-time field equal/after the query date-time).
From Date and time functions, you are looing for
DateTime.Today
DateTime.Today | CONVERT(date, GETDATE()) |
.FromSqlRaw()
.If you have better answer, please add a comment about this, thank you!