简体   繁体   中英

Enabling EF code first migrations V 4.3.1.0

I have worked with other migration projects and had no problem. in my current project i seperated the migration and model projects. I get the following error when adding migration or even when enabling migration (the configuration class is created):

PM> enable-migrations -Force No classes deriving from DbContext found in the current project. Edit the generated Configuration class to specify the context to enable migrations for. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly.GetTypes() at System.Data.Entity.ModelConfiguration.Mappers.TypeMapper.<.ctor>b_ 1(Assembly a) at System.Linq.Enumerable.d _14 2.MoveNext() at System.Collections.Generic.List 1.InsertRange(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.RetryLazy 2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer) at System.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) at System.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.ScaffoldRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Thanks

The message says that you have no class deriving from DbContext which means that you need to define one.

Something like this:

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)
   {}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM