【问题标题】:Why Identity 2.0 adds a new column in AspNetUserRoles when I extend IdentityUser?当我扩展 IdentityUser 时,为什么 Identity 2.0 在 AspNetUserRoles 中添加了一个新列?
【发布时间】:2014-11-05 19:50:25
【问题描述】:

我从 IdentityUser 派生了一个类 CustomUser。 如果我检查数据库表,我可以看到 Identity 2.0 向 AspNetUserRoles 表添加了第三列,称为 CustomUser_Id。

这似乎是我的 CustomUser 表的外键,但 AspNetUserRoles 已经有 UserId 列,所以它似乎是多余的。

为什么?我错过了什么?

【问题讨论】:

  • 你能贴一些代码吗?
  • 您是否为新的 CustomUser 正确使用了 EF 模型绑定。您可能需要继承 CandidateUser : IdentityUser
  • 抱歉的意思是说 CustomUser : IdentityUser。发布您的 IdentityDbContext 代码,必须正确继承

标签: c# asp.net-mvc asp.net-identity


【解决方案1】:

我假设你也有ApplicationUser 闲逛。 IdentityUser 是一个抽象类,因此dbo.AspNetUserRoles 中的列附加到用作泛型IdentityDbContext<TUser> 的TUser 类型的任何具体类。默认情况下,这是ApplicationUser。如果您创建了IdentityUser 的另一个子类,那么您所做的只是创建一个具有相似属性的类,但该类与所有身份信息完全断开,并且可能有自己的表dbo.CustomUsers,然后需要一个单独的表在dbo.AspNetUserRoles 上添加外键。

不管长短,你只能咬一口用户苹果。如果你想拥有不同类型的用户,他们需要继承你的主用户实现(默认为ApplicationUser),而不是IdentityUser。

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-14
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多