1
votes

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_142.MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, 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 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

1
Have you selected the project containing the DbContext in the dropdown in the package manager? - Not loved
yes,I did. still not working. - Guy

1 Answers

0
votes

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