EF 6 Enable-Migrations cannot find context

I am trying to configure the first migrations of EF code to EF 6.1.3-.NET 4.5.

There are several projects in my solution, the launch project is Songbirds.Web . I created a project called Songbirds.Dal.EntityFramework to contain my repositories, database context, and migrations.

I created my context class:

 namespace Songbirds.Dal.EntityFramework { public class SongbirdsDbContext : IdentityDbContext<ApplicationUser>, IUnitOfWork { public SongbirdsDbContext() : this("name=SongbirdsDBContext") { } ... } } 

The whole solution is built correctly, without errors.

I go into the Project Manager console and set the default project as Songbirds.Dal.EntityFramework and run the enable-migrations command, and I get the following error:

 PM> enable-migrations No context type was found in the assembly 'Songbirds.Dal.EntityFramework'. 

I tried to explicitly specify the context type with the following result:

 PM> enable-migrations -ContextTypeName Songbirds.Dal.EntityFramework.SongbirdsDbContext The context type 'Songbirds.Dal.EntityFramework.SongbirdsDbContext' was not found in the assembly 'Songbirds.Dal.EntityFramework'. 

SongbirdsDbContext is part of the Songbirds.Dal.EntityFramework project. Any ideas what I did wrong and why this does not recognize the context?

+6
source share
4 answers

I think I found the answer through the trial version and the error. First, I changed the context class to inherit it from the DbContext class instead of IdentifyDbContext:

 public class SongbirdsDbContext : DbContext 

And run the enable-migrations command to find the following error:

 Could not load file or assembly 'Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 

After adding the appropriate link to the required assembly, I was able to successfully complete the migration. I am not sure why inheritance from DbContext showed this error, while inheritance from IdentityDbContext was not.

+1
source

Verify that the project is set to the project by default using the EF context.

0
source

Try to run

 enable-migrations -ContextTypeName Songbirds.Dal.EntityFramework 

Adding .songBirdsContext to the end could be a problem.

0
source

I found a solution to this problem on my part in the fact that I just created a project, but have not yet created it. So building my project and re-executing the team worked

0
source

All Articles