提供程序,Oracle with Entity Framework不支持DeleteDatabase

时间:2013-06-19 17:24:17

标签: oracle entity-framework odac

我正在使用Model-First方法和Oracle数据库。

Update2:立即修复

在包含seed数据时,我收到此错误“提供商不支持DeleteDatabase”

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

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:此文件中出现的异常我知道当您第一次尝试访问数据库时,会执行种子数据方法或脚本。

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

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

REFERENCES 似乎我在这里遗漏了一些东西,因为没有任何与Oracle或ODAC相关的内容

References

堆栈跟踪

 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)

请在这里建议我缺少的东西。

1 个答案:

答案 0 :(得分:0)

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

将种子数据类更改为:

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();
    }

如果您不使用它可能出错:

  
      
  1. 提供商
  2. 不支持DeleteDatabase   
  3. 无法检查异常模型兼容性,因为未使用Code First模式创建DbContext实例。   从ObjectContext或使用EDMX创建的DbContext实例   无法检查文件的兼容性
  4.   

Microsoft链接Seeding database does not work

希望这有助于其他人。