Skip to content

UTC DateTime #2669

@btecu

Description

@btecu

After updating to the latest EF Core 3 and therefore Npgsql 4.0 I've started to have some issues - which might have been pre-existing or not.

Say I have a model:

public class Model {
  public int Id { get; set; }
  public string Name { get; set; }
  public DateTime Created { get; set; }
}

After updating to version 4, I noticed the following in the ContextModelSnapshot.cs:

b.Property<DateTime>("Created")
                        .HasColumnType("timestamp without time zone");

I've also noticed that although I save someDate.ToUniversaltTime(), it comes back with an unspecified kind.

What's the easiest solution for saving and retrieving UTC date times? What I need is to have it as Kind.UTC when retrieving it from the database.

I've been reading here http://www.npgsql.org/doc/types/datetime.html but there's no code example and I don't really understand where I'm supposed to set NpgsqlDbType.TimestampTz, to what I'm supposed to set it or even if this is the correct way.
I use Npgsql.EntityFrameworkCore.PostgreSQL exclusively, no SQL queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions