auto create database in Entity Framework Core

前端 未结 5 757
南笙
南笙 2020-11-29 17:43

My application which is being ported to .NET core will use the new EF Core with SQLite. I want to automatically create the database and table structures when the app is firs

5条回答
  •  囚心锁ツ
    2020-11-29 18:11

    If you get the context via the parameter list of Configure in Startup.cs, You can instead do this:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env,  LoggerFactory loggerFactory,
        ApplicationDbContext context)
     {
          context.Database.Migrate();
          ...
    

提交回复
热议问题