EF Core SQL Server uses GETDATE() in place of C# DateTime.Now

entity-framework-core sql-server

Question

I've noticed, that in case my C# query contains

(e => e.MyDateTimeData == DateTime.Now)

the generated SQL uses

WHERE [e].[MyDateTimeData] = GETDATE()

When the EF client timezone is different than the SQL Server host SQL Server process user timezone, this will not be good.

The timezones could be different even the client process and the SQL Server process run on the same host.

Missing I something, or is this a real issue?

1
4
5/20/2019 8:08:01 PM

Popular Answer

If you want to use the client time the then pass it in as a parameter, like this:

var dt = DateTime.Now;
. . .
var q = db.SomeTable.Where(e => e.MyDateTimeData == dt)
0
5/20/2019 8:41:05 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow