dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.78k stars 3.19k forks source link

migrationBuilder.InsertData should return SELECT scope_identity() to get LAST INSERT ID #34607

Closed hkusulja closed 2 months ago

hkusulja commented 2 months ago

This is a feature request for migrationBuilder and its InsertData method to return SELECT scope_identity() to get LAST INSERT ID.

This is currently supported outside of migrations, after context.SaveChanges();

Scenario: The case is when database does provide the Primary key / ID column. Example auto increment ID which is auto increment integer. After creating new migration, inside Up() you want to Insert Data. And then you want to insert another data, which is related to first insert data, you need to know the Id value which is provided by database, and should not be provided in c# code during Up() . Current workaround is to do manual SQL statement for getting this inside migration.

Current behavior:

Please improve this and support InsertData to return the database provided ID...

roji commented 2 months ago

Duplicate of #10000