How to deal with database changes during development with EF Core?

旧城冷巷雨未停 提交于 2019-12-05 21:01:24

Unfortunately it seems that EF core does not support automatic migrations like in EF 6. This means for every change you have to add a new migration. You can in your Startup => Configure add this code to automatically apply the latest migration but if i understand their documentation right you have to add a new migration for every change.

        using (var serviceScope app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
        {
            var context = serviceScope.ServiceProvider.GetRequiredService<YourDbContext>();
            context.Database.Migrate();
        }

Ref: EntityFramework Core automatic migrations https://github.com/aspnet/EntityFrameworkCore/issues/6214

Also agree with @Nathan about creating the structure yourself with fluent api.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!