Before updating scaffolding from new db schema try creating
If you are dealing the large database schema, this can be a very risky task.
In this article, we will address the above issues by providing solutions that can overcome the limitation of Entity Framework core migrations (many concepts can also be applied the legacy Entity Framework.) I invented this unique way of doing, when I had to solve a specific problem for managing Temporal Tables.
I have personally used the END migration to convert created tables to Temporal Tables. Just by changing the value, Visual Studio will reorder them.
You can insert a custom migration in the middle of generated migrations by naming it with a timestamp that is in between.
And the trigger’s job is to delete the record if it contains this migration id, 0_Custom Migration.
Let’s rename it to 0_Custom Migration_Run Every Time_At_START to reflect the class name. Important Note: Whichever folder this End migration lives in, that is where all the new migrations will be generated. To have several migrations run at the beginning, just same the Migrations in increasing values like: [Db Context(typeof(My Company DBContext))] [Migration("1_Custom Migration_Some Where Inthe Middle")] class Custom Migration_Some Where Inthe Middle : Migration [Db Context(typeof(My Company DBContext))] [Migration("2_Custom Migration_Some Where Inthe Middle")] class Custom Migration_Some Where Inthe Middle2 : Migration In order to Insert in the middle of any generated list of migrations, Just make sure you create timestamp that follow increasing order or simply rename all of your migrations starting with 1000 and go up.
Another thing you can do is you can organize files by renaming with a prefix number.
For instance, if you removed a record that creates a table Employee.
If you notice, you can see that files are in ascending order as per time stamp.
If I rename 20190107060526_Add Period Fields To to say 20180107060526_Add Period Fields To Employee, it will shuffle it to the top, because EF Core migrations are ordered based on date. See below, as soon as you change, the file is moved to top. We will see that it will run first, however it will only run once.
Once the migration is executed, it lives in your project having no function.
In fact, it is extremely risky to pick a specific migration and run because there is capability of managing repercussions of that run.