'Migrate data from one table to another in EF core code first approach

I am using a code-first approach in EF core, and I am in a situation where want to move a column from one table to another. My approach is to insert data using migration builder sql migrationBuilder.Sql("Insert query to new table"); and drop the column in the first table migrationBuilder.DropColumn(name: "FirstName", table: "Customer"); . Is there any better approach to migrate data from one table to another and drop the column from the first table?



Solution 1:[1]

I've used the same approach as what you're suggesting before and it has worked well for us. One of its benefits is that queries executed with migrationBuilder.Sql will be wrapped in the same transaction as the migration, so if the query fails or anything goes wrong then all migration changes are rolled back and you don't end up with a corrupted database.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Harden