I work with EF core and PostgreSQL
When configuring entity i use such code
modelBuilder.Entity(entityType.ClrType)
.Property("Created")
.IsRequired()
.HasDefaultValueSql("timezone('utc', NOW())");
And when i add new entity to db, it saves it with wrong time. I live on +3 tie zone, so saved datetime should be -3 from my current time. But it saves it with -6 from my current time, which is not how i expect utc time work.
But when i save data to db from PgAdmin, it saves correct time
How to fix this? And why does it happen
I tried using
.HasDefaultValue(DateTime.UtcNow)
But it only calculetes during migration creation and doesn’t work as default value i want.
Also when i use
.HasDefaultValueSql("NOW()");
It saves time from ef core like utc time, but when i save from pgAdmin in all time saves in my local time