EF migration MigrationBuilder.InsertData enables IDENTITY_INSERT when it is not needed. #11115
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-enhancement
Milestone
I'm trying to insert some data to DB via migration. I've discovered that it is possible via
MigrationBuilder.InsertData()
method.My environment:
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows Server 2016 Datacenter
IDE: Visual Studio 2017 Version 15.5.7
I've tried following
Here how it looks:
The Lookups table schema:
And it failed with following error:
Stack trace:
The issue here is that EF enables
IDENTITY_INSERT
but I'm actually OK with SQL Server generating ID value for me. After investigation it seems thatwas added to resulting SQL at https://github.com/aspnet/EntityFrameworkCore/blob/927082e095e9e937b3e684ecc8f2cc5d183a8634/src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs#L1057-L1091
Is there a way to disable such behavior somehow?
PS: I can create a repo for reproduction if details are not comprehensive enough.
The text was updated successfully, but these errors were encountered: