1

私は他の移行プロジェクトで作業しましたが、問題はありませんでした。現在のプロジェクトでは、移行プロジェクトとモデルプロジェクトを分離しました。移行を追加するとき、または移行を有効にするとき(構成クラスが作成されるとき)でも、次のエラーが発生します。

PM>enable-migrations-Force現在のプロジェクトでDbContextから派生したクラスが見つかりません。生成されたConfigurationクラスを編集して、移行を有効にするコンテキストを指定します。System.Reflection.ReflectionTypeLoadException:要求されたタイプの1つ以上をロードできません。詳細については、LoaderExceptionsプロパティを取得してください。System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)at System.Reflection.RuntimeModule.GetTypes()at System.Reflection.Assembly.GetTypes()atSystem.Data.Entity.ModelConfiguration.Mappers.TypeMapper。<。ctor>b_ 1(アセンブリa)at System.Linq.Enumerable.d _14 1.InsertRange 2.MoveNext() at System.Collections.Generic.List(Int32 index、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 input)at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context、XmlWriter writer)atSystem.Data.Entity.Migrations.Extensions.DbContextExtensions。<>c_ DisplayClass1 .b_0(XmlWriter w)at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)atSystem.Data.Entity。 Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration、DbContext usersContext)at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration)at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()のSystem.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()要求されたタイプの1つ以上をロードできません。詳細については、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 に答える