c# - 将 Microsoft.AspNetCore.Identity 默认表的 id 设置为 int
问题描述
我需要将所有默认 ID 设置为 int,但我只实现了一个新的用户类。我正在使用 Microsoft.AspNetCore.Identity 而不是 Microsoft.AspNet.Identity
我的用户是:
public class User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
DBAccessContext.cs 是:
public class DBAccessContext : IdentityDbContext<User>
{
public DBAccessContext(DbContextOptions<DBAccessContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
builder.Entity<User>(entity => { entity.ToTable(name: "Users");});
builder.Entity<IdentityRole>(entity => { entity.ToTable(name: "Roles"); });
builder.Entity<IdentityUserRole<string>>(entity => { entity.ToTable("Roles"); });
builder.Entity<IdentityUserClaim<string>>(entity => { entity.ToTable("Claims"); });
builder.Entity<IdentityUserLogin<string>>(entity => { entity.ToTable("Logins"); });
builder.Entity<IdentityRoleClaim<string>>(entity => { entity.ToTable("RoleClaims"); });
builder.Entity<IdentityUserToken<string>>(entity => { entity.ToTable("UserTokens"); });
//Calling the Seeding
builder.ApplyConfiguration(new RoleConfiguration());
}
}
最后配置如下:
public static void ConfigureIdentity(this IServiceCollection services)
{
var builder = services.AddIdentityCore<User>(q => { q.User.RequireUniqueEmail = true; });
builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), services);
builder.AddEntityFrameworkStores<DBAccessContext>().AddDefaultTokenProviders();
}
解决方案
我请你检查这个问题:
推荐阅读
- r - 左连接不重复相同的列
- php - 使用 find_files php 函数查找儿童文件夹
- linux - 相同版本的 jq 在 Ubuntu 16 和 Ubuntu 18 上的行为不同
- javascript - 如何将jinja2数据显示到javascript文件中
- bash - 如何为 sh 脚本中的前 n 个字节生成 MD5 哈希?
- java - 带有注释@PostConstruct(javax)的方法不会调用
- react-native - @expo/traveling-fastlane-darwin@1.10.0 的 npm WARN tarball 压缩包数据似乎已损坏。再试一次
- linux - 使用 Makefile 创建 .elf 文件
- html - 滚动时表格行内容渗入粘性标题内容 - 相对定位与绝对定位相关
- javascript - 如何将规范化 json 上的关系与 lodash 结合起来?