npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.53k stars 223 forks source link

PostgreSQL now() function gives different results EFCore and DBeaver #2824

Open tolgacakir opened 1 year ago

tolgacakir commented 1 year ago

First I try to execute from an app using EF Core 7 on my local system.

public class SqlResponse
{
    public DateTime Now { get; set; }
}
var sql = @"select now()::timestamp";
using IDbConnection con = _context.Database.GetDbConnection();
var result = (await con.QueryAsync<SqlResponse>(sql)).ToList();

result[0].Now returns 3.08.2023 11:00:23

Then I execute the query below on DBeaver. The DB is on remote machine.

SELECT now()::timestamp;

The query returns 2023-08-03 14:00:32.628 value.

My DB's timezone is Europe/Istanbul SHOW TIMEZONE;

TimeZone
Europe/Istanbul

And I check on my Windows 10 cmd line:

C:\Users\tolgacakir>tzutil /g
Turkey Standard Time

The NuGet packages that I used:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
roji commented 1 year ago

The QueryAsync API which you're executing on IDbConnection has nothing to do with EF, is that maybe Dapper?