npgsql and Entity Framework code first setup problems

落花浮王杯 提交于 2019-12-03 16:23:51

Npgsql doesn't support schema creation, so you have to create db manually. Then to avoid this error add this statement somewhere in your code (in your case it might be on the beginning of Main() function):

Database.SetInitializer<DataContext>(null);

Instead of DataContext use your DbContext implementation.

I agree with the previous answer by iwanek. To be a bit more specific, I like to place the statement in the OnModelCreating override method so that it is always called when the context is created.

    public class MyDbContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer<MyDbContext>(null);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!