DeleteDatabase is not supported by the provider, Oracle with Entity Framework

做~自己de王妃 提交于 2019-12-02 09:10:30

Way of seeding data using DropCreateDatabaseAlways or DropCreateDatabaseIfModelChanges is not supported in Model-First approach.

Change seed data class to:

public class ToolSeedData : IDatabaseInitializer<ToolContext>
{
    public void InitializeDatabase(ToolContext context)
    {
        var category = new List<CategoryValue>
        {
            new CategoryValue{Id=1, Name = "Associate"},
            new CategoryValue{Id =2, Name = "Professional"},
            new CategoryValue{Id=3, Name = "Master"},
            new CategoryValue{Id = 4, Name = "Product"},
            new CategoryValue{Id = 5, Name = "Portfolio"}
        };

        category.ForEach(cert => context.CategoryValues.Add(cert));

        context.SaveChanges();
    }

Possible error if you don't use it:

  1. DeleteDatabase is not supported by the provider
  2. Exception Model compatibility cannot be checked because the DbContext instance was not created using Code First patterns. DbContext instances created from an ObjectContext or using an EDMX file cannot be checked for compatibility

Microsoft link Seeding database does not work

Hope this helps someone else.

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