c# - ASP.NET Identity - 每种类型多个对象集

标签 c# asp.net asp.net-mvc entity-framework asp.net-identity

I got an error using ASP.NET Identity in my app. Multiple object sets per type are not supported. The object sets 'ApplicationRoles' and 'Roles' can both contain instances of type 'XXX.Identity.ApplicationRole'.

我在 stackoverflow 中看到了一些关于此错误的问题。全部表示同一类型的两个 DbSet 对象。但在我的 DbContext 中,没有相同类型的 DbSet。

当我想要启用自动迁移时抛出异常

我的上下文看起来像这样:

public class XXXDbContext :
        IdentityDbContext<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
    {
    public override IDbSet<ApplicationUser> Users { get; set; }
    public DbSet<ApplicationUserLogin> ApplicationUserLogins { get; set; }
    public DbSet<ApplicationUserRole> ApplicationUserRoles { get; set; }
    public DbSet<ApplicationUserClaim> AppApplicationUserClaims { get; set; 
    public DbSet<ApplicationRole> ApplicationRoles { get; set; }
    public DbSet<ApplicationAction> ApplicationActions { get; set; }
    public DbSet<ApplicationActionRole> ApplicationActionRoles { get; set; }
}

最佳答案

检查您的 IdentityDbContext,ApplicationRoles 已经定义,可能看起来像这样:

public System.Data.Entity.DbSet<ApplicationRoles> Roles{ get; set; }

删除那个,这个错误是在ApplicationRoles在XXXcontext中再次声明时出现的......

关于c# - ASP.NET Identity - 每种类型多个对象集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41823164/

相关文章:

javascript - 在不回发的情况下向 URL 添加/删除参数(查询字符串的功能)

c# - 我怎样才能得到 CheckBoxList 选定的值,我所拥有的似乎不起作用 C#.NET/VisualWebPart

c# - 如何将 reCAPTCHA 验证失败添加到 @html.ValidationSummary 列表中

asp.net-mvc - 绑定(bind)模型 Asp.net 输入类型 ="date"

c# - 如何使用 Microsoft.Web.Administration 命名空间在 IIS7 中干净地操作处理程序映射?

c# - 字符串太长时无法执行查询

asp.net - 在屏幕键盘上调出大写的文本输入

c# - MVC 4 - 脚本/CSS 渲染问题

c# - 一种抛出异常并记录它的方法

c# - 使用 Sendgrid 在 Azure 上发送简单的电子邮件