I\'ve added a separate Identification to the AspNetUsers table called NumericId that will serve along with the GUID like ID that ASP has for default.
I\'ve added the
Per the discussion on GitHub surrounding this issue, for EF Core 2.0 we needed to use both lines suggested in other posts.
for Entity framework core 2.0 , The "IsReadOnlyAfterSave" property is deprecated. Use following:
builder.Property(p => p.Id)
.UseSqlServerIdentityColumn();
builder.Property(p => p.Id)
.Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
Solution for asp.net core 3.1
modelBuilder.Entity<Type>().Property(u => u.Property).Metadata.SetAfterSaveBehavior(PropertySaveBehavior.Ignore);
If you are using EF Core 2.1, you can try that.
builder.Property(e => e.ColumnName).Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
It worked for me.
IsReadOnlyAfterSave is deprecated.
This line solved my problem. Available from 1.1.1
modelBuilder.Entity<ApplicationUser>().Property(u => u.NumberId).Metadata.IsReadOnlyAfterSave = true;
This was a bug with EF Core 1.0. See EF trying to Insert into Identity field.
EF Core 1.2 has marked the issue as fixed, but the workaround without updating is to use
modelBuilder.Entity<Type>().Property(u => u.Property).UseSqlServerIdentityColumn();
Using 3.1, the key is to make sure the identity value of the object you are updating matches the value of the record in the database. So if your object's ID is 0 but the id of the corresponding row in the database is 99, make sure the object's ID value is set to 99 before you try to save it.