Entity Framework Element Code First with DbUp

I am thinking of using Entity Framework 6 Code Firstto interact with the database along with DbUpupdating the database schema. The fact is that I do not want to use migration EFfor reasons. So, the workflow that I have achieved is:

  • Change the model (add POCOs, change properties, etc.)
  • Run Add-Migration temp_fileinVisual Studio Package Manager Console
  • Run Update-Database -ScriptinVisual Studio Package Manager Console
  • Take the generated scripts sql, including inserting a new row into the table__MigrationHistory
  • Create a new .sqlfile and earned scripts
  • Delete temp_file
  • Run dbup

It works great on local and production servers, however, I don’t feel comfortable adding and removing temp_fileevery time a new migration is created (I would like to have a constant stop temp_filebeing added to the solution.).

So the question is: Is there a better way to migrate a database using DbUpwith Entity Framework?

+4
source share
2 answers

In most cases, you can skip steps (2) and (6) using the Automatic first steps of the first code :

Automatic migration allows you to use Primary Code Migrations without having a code file in your project for every change you make .

. , , , db ( Configuration Migrations):

AutomaticMigrationsEnabled = true;

, :

  • , , .
  • ( , ).
  • , , EF , // .
  • ( ) EF Core, EF Core - , , .
+4

, , , , . Entity Framework ORM . DbUp SQL , . FluentMigrator DbUp. , #, . , , .. .

:

[Migration(1)]
public class CreateUserTable : Migration
{
    public override void Up()
    {
        Create.Table("Users");
    }

    public override void Down()
    {
        Delete.Table("Users");
    }
}
+1

Source: https://habr.com/ru/post/1692824/


All Articles