Entity framework 实体框架5.0 RC-包管理器命令';添加迁移&x27;由于假定缺少配置类型而失败

Entity framework 实体框架5.0 RC-包管理器命令';添加迁移&x27;由于假定缺少配置类型而失败,entity-framework,nuget,visual-studio-2012,database-migration,entity-framework-5,Entity Framework,Nuget,Visual Studio 2012,Database Migration,Entity Framework 5,使用Entity Framework 5.0.0 RC/EF 5.x DbContext Generator for C#/Visual Studio 2012 RC/.NET 4.0,我试图在我的项目中启用自动迁移。我在Package Manager控制台中运行了启用迁移: PM> enable-migrations No classes deriving from DbContext found in the current project. Edit the generated Co

使用Entity Framework 5.0.0 RC/EF 5.x DbContext Generator for C#/Visual Studio 2012 RC/.NET 4.0,我试图在我的项目中启用自动迁移。我在Package Manager控制台中运行了
启用迁移

PM> enable-migrations
No classes deriving from DbContext found in the current project.
Edit the generated Configuration class to specify the context to enable migrations for.
Code First Migrations enabled for project Test.
如您所见,它没有自动检测我的DbContext派生类型,但我通过在生成的代码文件
Migrations/Configuration.cs
中输入该类型的名称,很容易地解决了这个问题

但是,下一步,由于找不到上一步添加的迁移配置类型,Package Manager控制台命令
enable migrations
将失败

PM> add-migration Initial
No migrations configuration type was found in the assembly 'Test'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
我怎样才能解决这个问题

编辑:我发现可以使用参数
-ConfigurationTypeName
指定配置类型的名称:

PM> add-migration -ConfigurationTypeName Test.Migrations.Configuration Initial
The type 'Configuration' is not a migrations configuration type.
这仍然不起作用,但至少它阐明了为什么
添加迁移
bails,即它认为
Test.Migrations.Configuration
不是迁移配置类型。考虑到它是由enable-
迁移生成的,有人知道它为什么不被接受吗?请参见下面生成的代码以供参考(UserModelContainer派生自DbContext):

名称空间测试.迁移
{
使用制度;
使用System.Data.Entity;
使用System.Data.Entity.Migrations;
使用System.Linq;
使用测试模型;
内部密封类配置:DBMigOptionsConfiguration
{
公共配置()
{
AutomaticMiggerationsEnabled=假;
}
受保护的覆盖无效种子(UserModelContainer上下文)
{
//迁移到最新版本后将调用此方法。
//您可以使用DbSet.AddOrUpdate()助手扩展方法
//避免创建重复的种子数据。
//
//context.People.AddOrUpdate(
//p=>p.FullName,
//新人{FullName=“安德鲁·彼得斯”},
//新人{FullName=“Brice Lambson”},
//新人{FullName=“Rowan Miller”}
//    );
//
}
}
}

问题是我在针对.NET Framework 4.5时安装了Entity Framework 5.0.0 RC。由于部署到WindowsAzure,我发现我必须以.NET4.0为目标。我不知道NuGet的复杂之处,但为.NET4.5安装的EF包似乎不能与我的4.0目标项目正常工作


在重新安装EF NuGet软件包后,虽然我的项目目标是.NET 4.0,但一切都很好。

您的解决方案中有多个项目吗?顺便说一句,您提到您正在使用DbContext生成器-迁移只针对代码优先。@LadislavMrnka啊,可能就是这样,我首先想到的是模型。我对实体框架不太了解,而且我总是先以可视化的方式设计模型。我将研究代码优先的方法,看看是否必须切换到该方法。我不太明白如果代码是从模型生成的,会有什么不同。我不确定这一限制是否没有从5.0RC中删除,但以前的版本在您尝试迁移不是先用代码创建的模型时出错。无论如何,这个错误应该稍后抛出-您的问题可能与此无关。@LadislavMrnka是的,关于错误的实际原因的不确定性确实令人沮丧:(顺便说一句,解决方案只有一个项目。@LadislavMrnka我现在尝试了代码优先的方法,自己定义了数据库模型和上下文类,但得到了完全相同的错误:(如果您有兴趣添加您的投票,这里有一个NuGet错误:迷宫不是很可怕吗。啊哈。Microsoft Visual Studio Professional 2013版本12.0.31101.00 Update 4 Package Manager控制台主机版本2.8.50926.663问题仍然存在。感谢您提供详细说明和解决方案。
namespace Test.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using Test.Models;

    internal sealed class Configuration : DbMigrationsConfiguration<UserModelContainer>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(UserModelContainer context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}