【发布时间】:2021-09-16 12:39:04
【问题描述】:
这是我将其他字段添加到 ASPNetUsers 表的 ApplicationDbContext.cs 代码。我注意到数据库中的 Identity 生成表将主键 Id 设置为 nvarchar (450)。如何通过代码优先迁移方法将 ASPNetUsers 的 Id 更改为 bigint (Int64)?
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(100)]
public string FirstName { get; set; }
[Required]
[StringLength(100)]
public string LastName { get; set; }
[Required]
[Column(TypeName = "VARCHAR")]
[StringLength(20)]
public string SAPNo { get; set; }
[Required]
[Column(TypeName = "VARCHAR")]
[StringLength(150)]
public string Position { get; set; }
[Required]
[Column(TypeName = "VARCHAR")]
[StringLength(150)]
public string EmailAddress { get; set; }
[Required]
public Int64 DepartmentId { get; set; }
[Required]
public int LocationId { get; set; }
[Required]
public int RoleId { get; set; }
[Column(TypeName = "VARCHAR")]
[StringLength(20)]
public string CreatedBy { get; set; }
public string CreatedDate { get; set; }
public bool IsActive { get; set; } = true;
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
【问题讨论】:
-
为什么要把users表的pk改成
int?使用Guids 作为 users/roles 表上的主键的有趣之处在于它们是随机的,不能那么容易猜到。
标签: asp.net-core asp.net-core-mvc asp.net-identity asp.net-core-5.0