You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're using Seed-Data with EF.Migrations with Value-Generators, initial values are not created with "ValueGeneratedOnAddOrUpdate()" but only with "ValueGeneratedOnAdd()".
see my PR: #21865
Problem seems to be the equality-comparison of a flag enum!
Steps to reproduce
TimedEntity.cs (abstract)
publicabstractclassTimedEntity{[Column("created_at")]publicDateTimeOffsetCreatedAt{get;}[Column("updated_at")]publicDateTimeOffsetUpdatedAt{get;}// notice: not nullable here!}
varvoucher=modelBuilder.Entity<Voucher>();voucher.Property(x =>x.CreatedAt).ValueGeneratedOnAdd().HasValueGenerator<NowValueGenerator>();voucher.Property(x =>x.UpdatedAt).ValueGeneratedOnAddOrUpdate().HasValueGenerator<NowValueGenerator>();// notice: generate value on ADD *OR* UPDATE!voucher.HasData(newVoucher(){Code="ABC1234",Id=1});// no definition of createdAt or updatedAt here - should be filled out automatically
@thehe ValueGenerated configuration only affects values generated by the database, you don't need to specify them when using a client value generator. Also a value generator isn't currently used when updating, see #6999
Why there is "created_at" then in the seed data and not "updated_at"?
When it shouldn't do anything regarding the client-side ValueGenerator, then there shouldn't be any difference between resulting "createdAt" and "updatedAt"?
But "updatedAt" is just missing in seed data.
Can you please describe what's preventing "updated_at" to get popoluted by the same exact value-generator (which just pushes out "DateTimeOffset.UtcNow" as value)
When you configure a property as ValueGeneratedOnAddOrUpdate EF assumes that the value will always be provided by the database, therefore one supplied in the insert operation would either be ignored or cause an error. However for ValueGeneratedOnAdd many databases do provide a way of provided a value that would override what would be generated by the database.
Usually the table auditing pattern is implemented purely on the database side, as that provides the most consistent values.
If you're using Seed-Data with EF.Migrations with Value-Generators, initial values are not created with "ValueGeneratedOnAddOrUpdate()" but only with "ValueGeneratedOnAdd()".
see my PR: #21865
Problem seems to be the equality-comparison of a flag enum!
Steps to reproduce
TimedEntity.cs (abstract)
Voucher.cs
Migrations seed data - OnConfiguring:
Results in:
Further technical details
EF Core version: 3.1.6
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL (but irrelevant)
Target framework: .NET Core 3.1
Operating system: RHEL7, RHEL8, Win10 Enterprise 20H2
IDE: VSCode, Visual Studio 2019 pro
The text was updated successfully, but these errors were encountered: