使用ninject标识ApplicationDbContext

时间:2015-03-15 10:39:17

标签: asp.net-mvc entity-framework asp.net-identity

我正在为我的实体使用ninject并创建了一个自定义dbcontext,它保存了我的poco类。这是 CusDbContext 。然后我通过在 ApplicationDbContext

的基类构造函数中将它添加为参数来将* this添加到identity中
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("CusDbContext", throwIfV1Schema: false)
    {
    }

现在在我的webconfig中,连接字符串设置为CusDbContext。一切正常。在初始创建(当我注册用户并且.net在后台创建所有用户表的数据库时) 此数据库是本地的(本地)\ v11.0

创建表并添加用户,一切正常。然后,当我首先为代码添加迁移时,它会说明

  

在程序集中找到了多个上下文类型

酷,所以我使用 CusDbContext

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

我得到了错误

  

Library.Data.Concrete.IdentityUserLogin :: EntityType   &#39; IdentityUserLogin&#39;没有定义键。为此定义密钥   的EntityType。

这是一个viewModel虽然(O.o)

为什么迁移会尝试将viewmodel添加为实体?有没有办法让一个上下文类型使用身份默认文件?我还是想用ninject。

1 个答案:

答案 0 :(得分:0)

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

ApplicationDbContext需要这个才能构建。

相关问题