具有 ninject 的身份 ApplicationDbContext

Identity ApplicationDbContext with ninject

我正在为我的实体使用 ninject,并创建了一个自定义 dbcontext,其中包含我的 poco classes。这是 CusDbContext 。然后,我通过将 *this 作为参数添加到 ApplicationDbContext

的基础 class 构造函数中来将其添加到标识中
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("CusDbContext", throwIfV1Schema: false)
    {
    }

所以现在在我的 webconfig 中,连接字符串设置为 CusDbContext。这一切都很好。在初始创建时 (当我注册用户并且 .net 在后台使用所有用户表创建数据库时) 顺便说下这个数据库是本地的(local)\v11.0

表已创建并添加了用户,一切正常。然后当我首先为代码添加迁移时,它指出

More than one context type was found in the assembly

很酷,所以我使用我的 CusDbContext

PM>Enable-Migrations -ContextTypeName Library.Data.Concrete.CusDbContext
PM>Add-Migration init

我得到了错误

Library.Data.Concrete.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.

不过那是一个 viewModel (O.o)

为什么迁移尝试将视图模型添加为实体?有什么方法可以使用身份默认文件来获得一种上下文类型吗?我还是想用ninject。

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }

为了构建,ApplicationDbContext 需要它。