EF 6启用 - 迁移无法查找上下文

A. *_*ith 6 c# entity-framework ef-migrations

我试图在EF 6.1.3 - .NET 4.5中设置EF代码首次迁移.

我的解决方案中有多个项目,启动项目正在进行中Songbirds.Web.我创建了一个名为Songbirds.Dal.EntityFramework包含我的存储库,数据库上下文和迁移的项目.

我创建了我的上下文类:

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

整个解决方案构建正确,没有错误.

我进入项目管理器控制台并将默认项目设置为Songbirds.Dal.EntityFramework并运行enable-migrations命令,我收到以下错误:

PM> enable-migrations
No context type was found in the assembly 'Songbirds.Dal.EntityFramework'.
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下结果显式指定Context Type:

PM> enable-migrations -ContextTypeName Songbirds.Dal.EntityFramework.SongbirdsDbContext
The context type 'Songbirds.Dal.EntityFramework.SongbirdsDbContext' was not found in the assembly 'Songbirds.Dal.EntityFramework'.
Run Code Online (Sandbox Code Playgroud)

SongbirdsDbContext是Songbirds.Dal.EntityFramework项目的一部分.我做错了什么想法以及为什么它没有认识到背景?

A. *_*ith 1

我想我通过反复试验找到了答案。我首先将上下文类更改为从 DbContext 类继承,而不是IdentifyDbContext:

public class SongbirdsDbContext : DbContext
Run Code Online (Sandbox Code Playgroud)

并重新运行enable-migrations命令发现如下错误:

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.
Run Code Online (Sandbox Code Playgroud)

添加对所需程序集的适当引用后,我能够成功启用迁移。我不确定为什么从 DbContext 继承会显示此错误,而从 IdentityDbContext 继承则不会。