I need help to clarify how EF Code First Migrations works on production machine. I've some entity classes and DbContext-derived class to access entities. Now, I want to perform these several things:
I've read some articles about migrations, but they're focused mostly on NUGET usage or pure automatic database updates at run-time (via MigrateDatabaseToLatestVersion
). I know about DbMigration
class, but I can't understand, how to glue together MigrateDatabaseToLatestVersion
strategy and DbMigration
.
UPDATE.
In fact, I cannot use NUGET in the project and I need possibility to make a migration "by hand".
Simply use MigrateDatabaseToLatestVersion
.
when my application starts, it must create database, if database does not exists;
MigrateDatabaseToLatestVersion
will do that
then database schema must be adjusted to the model;
MigrateDatabaseToLatestVersion
will do that
if database was created just now, I want to create some indexes;
Create code based initial migration for your database and Sql
method in Up
method to define all indexes you need.
also, if database was created just now, it must be seeded by some initial data;
Again use Sql
in initial migration or Seed
method in migration configuration
all of these things must be performed automatically, without any NUGET commands or external tools
NuGet and commands will help you to prepare it in design time (but you can simply reference required assemblies and write all code yourselves). Runtime doesn't need any powershell commands.
DbMigrator
is for scenarios where you don't want to use MigrateDatabaseToLatestVersion
and you want to control migration from your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With