EF Core 5 with TPT for IdentityUser

问题描述

我正在尝试设置一个包含多个 IdentityUser 的项目。使用 EF 5 Core(代码优先)应该可以使用 TPT(每个类型的表)。但出于某种原因,实体是在单个表中创建的。

这是我的代码

function weighted_random (weights)
    local summ = 0
    for i,weight in pairs (weights) do
        summ = summ + weight
    end
    local value = math.random (summ)
    summ = 0
    for i,weight in pairs (weights) do
        summ = summ + weight
        if value <= summ then
            return i,weight
        end
    end
end

当我运行 local elements = {"a","b","c","d"} -- elements local weights = {40,24,22,14} -- weights of elements local n = weighted_random (weights) -- returns 1,2,3 or 4 local element = elements[n] -- returns "a","c" or "d" -- with chances: 40/100,24/100,22/100,14/100,as in weights 时,它会创建一个迁移,其中 public class AppDbContext : IdentityDbContext<User,Role,int> { public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Teacher>().ToTable("Teachers"); modelBuilder.Entity<Student>().ToTable("Students"); base.OnModelCreating(modelBuilder); } public DbSet<Teacher> Teachers { get; set; } public DbSet<Student> Students { get; set; } } public class User : IdentityUser<int> { } public class Role : IdentityRole<int> { } public class Teacher : User { public string Name { get; set; } public string JobTitle { get; set; } } public class Student : User { public string Name { get; set; } public string Major { get; set; } } Add-Migration 属性都放置在 Teacher 表中。

在使用 EF Core 5 时,它不应该为 StudentAspNetUsers 创建单独的表吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)