提供程序不支持DeleteDatabase,带有实体框架的Oracle [英] DeleteDatabase is not supported by the provider, Oracle with Entity Framework

查看:102
本文介绍了提供程序不支持DeleteDatabase,带有实体框架的Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用模型优先"方法和Oracle数据库.

I'm using Model-First approach and Oracle database.

Update2:立即修复

在包含seed数据时,出现此错误提供商不支持DeleteDatabase"

On including seed data, I'm getting this error "DeleteDatabase is not supported by the provider"

UPDATE1 如果我从
更改种子数据类型 public class MySeedData : DropCreateDatabaseAlways<ToolContext>
public class MySeedData : DropCreateDatabaseIfModelChanges<ToolContext>
此错误被另一个错误替换:

UPDATE1 If I change seed data type from
public class MySeedData : DropCreateDatabaseAlways<ToolContext> to
public class MySeedData : DropCreateDatabaseIfModelChanges<ToolContext>
this error is replaced by another error:

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

种子数据

 public class MySeedData : DropCreateDatabaseAlways<ToolContext>
    {
        protected override void Seed(ToolContext context)
        {
            base.Seed(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();
        }
    }

Web.Config

 <connectionStrings>
    <add name="LMSPriorToolContext" 
           connectionString="metadata=res://*/Models.LMSPriorToolModel.csdl|res://*/Models.LMSPriorToolModel.ssdl|res://*/Models.LMSPriorToolModel.msl;
provider=Oracle.DataAccess.Client;
provider connection string=&quot;DATA SOURCE=DEV;PASSWORD=1234;PERSIST SECURITY INFO=True;USER ID=abc&quot;" 
providerName="System.Data.EntityClient" />
  </connectionStrings>

Application_Start()

Database.SetInitializer<ToolContext>(new SeedData());

Main.cs:该文件引发异常我知道您第一次尝试访问数据库时,将执行种子数据方法或脚本.

Main.cs: EXCEPTION RAISED IN THIS FILE I know when you first try to access database, seed data method or scripts are executed.

 using (var dbContext = new ToolContext())
        {
            var items = dbContext.CategoryValues;

            foreach(CategoryValue category in **items**)  // **Getting error here**
            {
                Console.WriteLine(category.Name);
            }
        }

参考,似乎这里缺少一些内容,因为与Oracle或ODAC没有任何关系

REFERENCES Seems like I'm missing something here as there is nothing related to Oracle or ODAC

堆栈跟踪

 at System.Data.Common.DbProviderServices.DbDeleteDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Objects.ObjectContext.DeleteDatabase()
   at System.Data.Entity.Internal.DatabaseOperations.DeleteIfExists(ObjectContext objectContext)
   at System.Data.Entity.Database.Delete()
   at System.Data.Entity.DropCreateDatabaseAlways`1.InitializeDatabase(TContext context)
   at System.Data.Entity.Database.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)

请提出我在这里想念的内容.

Please suggest what I'm missing here.

推荐答案

模型优先"方法不支持使用DropCreateDatabaseAlways or DropCreateDatabaseIfModelChanges进行数据播种的方式.

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

将种子数据类更改为:

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
  2. 异常无法检查模型兼容性,因为DbContext实例不是使用Code First模式创建的. 从ObjectContext或使用EDMX创建的DbContext实例 无法检查文件的兼容性
  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链接

Microsoft link Seeding database does not work

希望这对其他人有帮助.

Hope this helps someone else.

这篇关于提供程序不支持DeleteDatabase,带有实体框架的Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆