Entity Framework 5.0 RC - Package Manager command 'add-migration' fails due to supposedly missing configuration type
我正在使用用于C#/ Visual Studio 2012 RC / .NET 4.0的Entity Framework 5.0.0 RC / EF 5.x DbContext生成器,试图在项目中启用自动迁移。我已经在Package Manager控制台中运行
1 2 3 4 | 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派生类型,但是我可以通过在生成的代码文件
但是,由于找不到上一步添加的迁移配置类型,下一步,包管理器控制台命令
1 2 | 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). |
我该如何解决?
编辑:我发现我可以使用参数
1 2 | PM> add-migration -ConfigurationTypeName Test.Migrations.Configuration Initial The type 'Configuration' is not a migrations configuration type. |
这仍然行不通,但是至少可以阐明为什么
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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" } // ); // } } } |
问题出在我针对.NET Framework 4.5时安装了Entity Framework 5.0.0 RC。 由于部署到Windows Azure,我发现我不得不以.NET 4.0为目标。 我不知道NuGet的复杂性,但是为.NET 4.5安装的EF软件包似乎无法与我的4.0目标项目一起正常工作。
重新安装EF NuGet程序包后,将我的项目定位于.NET 4.0,一切正常。