1

我曾与其他迁移项目合作过,没有任何问题。在我当前的项目中,我将迁移和模型项目分开。添加迁移甚至启用迁移(已创建配置类)时出现以下错误:

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(程序集 a)在 System.Linq.Enumerable.d _14 1.InsertRange 2.MoveNext() at System.Collections.Generic.List(Int32 索引,IEnumerable 1 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 context, XmlWriter writer) 在 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 context) 在 System.Data.Entity。 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) 的 Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置,DbContext usersContext) System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

谢谢

4

1 回答 1

0

该消息说您没有从 DbContext 派生的类,这意味着您需要定义一个。

像这样的东西:

class MyContext: DbContext
{
   public DBSet<Some_Entity_Which_Represent_DB_table> SetName {get;set;}

   public MyContext() : base(here you can specify database with its name or connectionString or leave it empty)
   {}
}
于 2012-10-15T14:35:43.107 回答