Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core 6.0 release and breaking change notes #116

Merged
merged 3 commits into from
Sep 24, 2021

Conversation

roji
Copy link
Member

@roji roji commented Sep 24, 2021

Includes documentation on the timestamp handling changes.

Closes #115

@vonzshik @NinoFloris this is the EF Core side of things - I will work on the ADO.NET notes later today.

(don't forget these are docs so we can always improve them later - we should merge these soon since that needs to happen before we release rc1)

Includes documentation on the timestamp handling changes.

Closes npgsql#115
@roji roji merged commit 58a6507 into npgsql:main Sep 24, 2021
@roji roji deleted the EFTimestampStuff branch September 24, 2021 07:31
github-actions bot pushed a commit that referenced this pull request Sep 24, 2021
@Arth-OOZEE
Copy link

image
getting error while saving datetime column to database (postgresql)

@Tieantono
Copy link

image getting error while saving datetime column to database (postgresql)

Check this documentation: https://www.npgsql.org/efcore/release-notes/6.0.html#nodatime-changes

Example codes:

var currentDate = DateTimeOffset.UtcNow.DateTime;
// Specify the DateTimeKind here.
currentDate = DateTime.SpecifyKind(updatedAt, DateTimeKind.Utc);

// Your entity object, let's say you have a table named `employee`.
var employee = new Employee
{
    Id = Guid.NewGuid(),
    // Your `created_at` column with data type timestamp with time zone / timestamptz.
    CreatedAt = currentDate
}
_dbContext.Employees.Add(employee);
_dbContext.SaveChanges();

@roji
Copy link
Member Author

roji commented Nov 17, 2021

@Tieantono please open a new issue with a runnable code sample rather than posting on this PR.

FYI here's a minimal code sample which shows the above working with 6.0.

Code sample
await using var ctx = new EmployeeContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();

var currentDate = DateTime.UtcNow;

// Your entity object, let's say you have a table named `employee`.
var employee = new Employee
{
    Id = Guid.NewGuid(),
    // Your `created_at` column with data type timestamp with time zone / timestamptz.
    CreatedAt = currentDate
};
ctx.Employees.Add(employee);
ctx.SaveChanges();

public class EmployeeContext : DbContext
{
    public DbSet<Employee> Employees { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseNpgsql(@"Host=localhost;Username=test;Password=test")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();
}

public class Employee
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public DateTime CreatedAt { get; set; }
}

@Tieantono
Copy link

@roji Hi, I was just giving @Arth-OOZEE an example, not asking for a solution, but your example simpler than mine, I forgot that you could DateTime.UtcNow to obtain the DateTime object with UTC value, thanks.

@roji
Copy link
Member Author

roji commented Nov 17, 2021

@Tieantono oh sorry, I missed that - thanks for helping out! @Arth-OOZEE please open a new issue if you continue to run into trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document NodaTime translations
4 participants