【发布时间】:2012-09-15 02:33:51
【问题描述】:
我曾参与过其他迁移项目,没有遇到任何问题。在我当前的项目中,我将迁移和模型项目分开。添加迁移甚至启用迁移(已创建配置类)时出现以下错误:
PM> enable-migrations -Force 找不到从 DbContext 派生的类 在当前项目中。将生成的配置类编辑为 指定启用迁移的上下文。 System.Reflection.ReflectionTypeLoadException:无法加载一个或 更多请求的类型。检索 LoaderExceptions 属性 了解更多信息。在 System.Reflection.RuntimeModule.GetTypes(RuntimeModule 模块)在 System.Reflection.RuntimeModule.GetTypes() 在 System.Reflection.Assembly.GetTypes() 在 System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.<.ctor>b_1(Assembly a) 在 System.Linq.Enumerable.d_14
2.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 索引, IEnumerable1 collection) at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper..ctor(MappingContext mappingContext) at System.Data.Entity.DbModelBuilder.MapTypes(EdmModel model) at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput 输入) 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
在 System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
在 System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext 上下文,XmlWriter 作家)在 System.Data.Entity.Migrations.Extensions.DbContextExtensions.c_DisplayClass1.b_0(XmlWriter w) 在 System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml) 在 System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext 上下文)在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置,DbContext usersContext)在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置)在 System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration 迁移配置)在 System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() 在 System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。
谢谢
【问题讨论】:
-
你是否在包管理器的下拉列表中选择了包含 DbContext 的项目?
-
是的,我做到了。还是不行。
标签: c# entity-framework