【问题标题】:Why does the Identity v2 naming schema differ between EF and AspNet?为什么 EF 和 AspNet 的 Identity v2 命名架构不同?
【发布时间】:2014-10-03 16:17:45
【问题描述】:

我想知道是否有人可以帮助我解决以下问题...

我创建了一个使用 Identity v2 的 EF 代码优先数据库 (sqlexpress) - 我可以在该数据库中看到我的所有模型,包括以 Identity* 开头的与身份相关的表(即 IdentityUserClaims、IdentityUserLogins、IdentityUserRoles IdentityRoles 和 IdentityUsers )。

然后我创建一个全新的 MVC 项目并添加相同的连接字符串。当我注册一个新用户时 - 由于某种原因,它会关闭并创建以 AspNet* 开头的 Identity v2 表(即 AspNetUserClaims、AspNetUserLogins、AspNetUserRoles AspNetRoles 和 AspNetUsers)。

[我正在使用... EF 6.1.1、Identity 2.1、MVC 5.2]

为什么 EF 和 AspNet 的 Identity 命名架构不同?如何让 MVC 使用 EF 架构 Identity*?

【问题讨论】:

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


    【解决方案1】:

    您可以通过类顶部的[Table("MyUsers")] 属性覆盖表名:

    [Table("WhateverILikeUsers")]
    public class ApplicationUser : IdentityUser
    {
    }
    

    或者您可以重命名 DbContext 中的表:

    public class MyContext : IdentityDbContext<ApplicationUser>
    {
        // other stuff
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ApplicationUser>().ToTable("HelloIdentity");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 2014-01-29
      • 2022-10-06
      • 2013-07-16
      • 2017-06-28
      • 1970-01-01
      • 2020-09-14
      相关资源
      最近更新 更多