How to apply migrations from code (EF Core)

前端 未结 3 1272
离开以前
离开以前 2020-12-15 06:42

How to apply migrations from code

for EF6 work code

    Database.SetInitializer(null);
    var settings = new MigrationsConfiguratio         


        
相关标签:
3条回答
  • 2020-12-15 06:50

    According to the Microsoft documentation, for more advanced scenarios than simply applying the migrations which are already present in your project file structure, you can use the EF Core IMigrator service. You can easily access the internal implementation by utilizing the following access code:

    var migrator = myDbContext.GetInfrastructure().GetService<IMigrator>();
    
    0 讨论(0)
  • 2020-12-15 06:56

    For Entity Framework Core 1.0.0, ensure you have the Microsoft.EntityFrameworkCore.Relational NuGet package. Then import this namespace:

    using Microsoft.EntityFrameworkCore;
    

    Finally, get hold of a DbContext and run:

    context.Database.Migrate();
    
    0 讨论(0)
  • 2020-12-15 07:07

    In beta 7 and on, use:

    using Microsoft.Data.Entity;
    
    ...
    
    context.Database.Migrate();
    
    0 讨论(0)
提交回复
热议问题