我正在开发一个多租户应用程序ASP.NET Core 2.1
。我正在利用AspNetCore.Identity.EntityFrameworkCore
框架进行用户管理。我想在表中添加一个唯一索引。此外,在用户表和表中。NormalizedName
TenantId
Role
NormalizedUserName
TenantId
User
这不允许我创建该索引,因为身份为角色表RoleNameIndex
和UserNameIndex
用户表创建了默认的唯一索引。OnModelCreating
在 EF Core中配置该方法的最佳方法是什么?
modelBuilder.Entity<User>().HasIndex(u => new { u.NormalizedUserName, u.TenantId }).HasName("UserNameIndex").IsUnique(true);
modelBuilder.Entity<Role>().HasIndex(u => new { u.NormalizedName, u.TenantId }).HasName("RoleNameIndex").IsUnique(true);