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
After scaffolding a database with the Migration tool, I am attempting to seed a database using data pulled from an existing database. This data has been generated using the Generate Scripts tool inside SSMS and then converted to code (lists of data models) and then called by using Entity.AddRange().
Many of the entities have pre-existing relationships & keys that need to be preserved for the application to function properly. I attempted to use a number of different methods to allow for SET IDENTITY_INSERT ON but nothing I have tried has worked.
If you are seeing an exception, include the full exceptions details (message and stack trace).
Microsoft.EntityFrameworkCore.DbUpdateException occurred
HResult=0x80131500
Message=An error occurred while updating the entries. See the inner exception for details.
Source=<Cannot evaluate the exception source>
StackTrace:
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func`2 operation, Func`2 verifySucceeded, TState state)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at CmsDatabaseSeed.CmsDatabaseContext.EnsureSeedData() in
Inner Exception 1:
SqlException: Cannot insert explicit value for identity column in table 'AclsRef' when IDENTITY_INSERT is set to OFF.
Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
@JT-Bruch This is the same issue as described here: #703. Are you sure that you are setting IDENTITY_INSERT on for the correct table? In the SQL you posted it is set on for AclsRef, but then the insert is for Acls.
After scaffolding a database with the Migration tool, I am attempting to seed a database using data pulled from an existing database. This data has been generated using the
Generate Scripts
tool inside SSMS and then converted to code (lists of data models) and then called by usingEntity.AddRange()
.Many of the entities have pre-existing relationships & keys that need to be preserved for the application to function properly. I attempted to use a number of different methods to allow for
SET IDENTITY_INSERT ON
but nothing I have tried has worked.If you are seeing an exception, include the full exceptions details (message and stack trace).
Steps to reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
EntityTable DataModel
ModelCreation
Context Setup
EnsureSeedData Attempt #1
EnsureSeedData Attempt #2
This is the log for the above.
Still fails.
EnsureSeedData Attempt #3
This is the exception for the above.
Still fails.
Further technical details
EF Core version: 1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: