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
Below code (simulated to show relevant parts) throw "Cannot update identity column 'ModelID'" exception.
classModel{[Key][DatabaseGenerated(DatabaseGeneratedOption.Identity)][Column("ModelID")]publicintModelId{get;set;}publicDateTimeModelDate{get;set;}publicintEntityId{get;set;}[Column("EntityTypeID")]publicintEntityTypeId{get;set;}[Column("DataTypeID")]publicintDataTypeId{get;set;}// More fields}
varupdateByProperties=newList<string>{nameof(Model.ModelDate),nameof(Model.EntityId),nameof(Model.EntityTypeId),nameof(Model.DataTypeId)};context.BulkInsertOrUpdate(modelList,newBulkConfig{UpdateByProperties=updateByProperties}});// Properties given in UpdateByProperties should be used to match records. It's unique key on table.// The inserted entries have ModelId set to zero// BulkInsertOrUpdate (Or BulkUpdate) throws "Cannot update identity column 'ModelID'"
I also tried below as well based on certain suggestions I saw regarding this topic for Entity framework core - but didn't help
entity.HasAlternateKey(x =>x.ModelId).HasName("ModelID");entity.Property(p =>p.ModelId).ValueGeneratedOnAdd();// this should have same effect as UseSqlServerIdentityColumn though
I also tried SetOutputIdentity, KeepIdentity even though it didn't look like related to the issue.
If I do not include UpdateByProperties, it doesn't throw any exception but it doesnt work as expected.
BulkUpdate does nothing while BulkInsertOrUpdate does an insert which is not the expectation.
The text was updated successfully, but these errors were encountered:
Additinaly you don't need any of the PK config since EF by convention makes Identity column if one is named Id/ID or TableNameId/ID.
So Attributes [Key], [DatabaseGenerated] can be removed as well as code from builder regarding the same.
PS
When adding code snippets into the comment use code formatting segment for C# for better readability.
```C#
// code goes here
```
I have edited(formatted) your question accordingly.
Below code (simulated to show relevant parts) throw "Cannot update identity column 'ModelID'" exception.
Context
Insert/Update code
I also tried below as well based on certain suggestions I saw regarding this topic for Entity framework core - but didn't help
I also tried SetOutputIdentity, KeepIdentity even though it didn't look like related to the issue.
If I do not include UpdateByProperties, it doesn't throw any exception but it doesnt work as expected.
BulkUpdate does nothing while BulkInsertOrUpdate does an insert which is not the expectation.
The text was updated successfully, but these errors were encountered: