-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 5.0 doesn't detect change to DateTimeOffset's offset #24567
Comments
I can't reproduce it, |
Here is a more comprehensive repro, using the InMemoryDatabase provider. Program.cs
.csproj
|
I can confirm this repros - and as @clement911 wrote this is due to the equality behavior .NET defines for DateTimeOffset, which doesn't take timezone differences into account. |
Thanks @roji , can this be prioritized for the next release? |
@clement911 I've submitted a fix for this. In the meantime you can set up your own value comparer with the right behavior as described in the docs: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().Property(b => b.DateTimeOffset)
.Metadata
.SetValueComparer(new ValueComparer<DateTimeOffset>(
(dto1, dto2) => dto1 == dto2 && dto1.Offset == dto2.Offset,
dto => dto.GetHashCode()));
} |
Awesome. Thanks for the quick fix! |
I see the following bug with EF 5.0
I believe this happens because
IEquatable<DateTimeOffset>
considers that twoDateTimeOffset
s are equal if they represent the same absolute time.However, from a DB perspective, the code above should detect the change and persist the new offset in the column (which is of type
datetimeoffset
in Sql Azure)The text was updated successfully, but these errors were encountered: