Asp.net core 无法在Aspnetuser表中添加其他字段

Asp.net core 无法在Aspnetuser表中添加其他字段,asp.net-core,ef-code-first,asp.net-identity,Asp.net Core,Ef Code First,Asp.net Identity,我已经创建了一个自定义字段,并尝试在aspnetusers表中插入自定义字段,但没有插入附加的fiels数据。下面是我尝试的代码: var identityUser = new CreateUser { Email = model.Email, UserName = model.Email, TenantId = obj.ToString(),

我已经创建了一个自定义字段,并尝试在aspnetusers表中插入自定义字段,但没有插入附加的fiels数据。下面是我尝试的代码:

            var identityUser = new CreateUser
            {

                Email = model.Email,
                UserName = model.Email,
                TenantId = obj.ToString(),
                IsAdmin= true


            };
            var result = await _userManager.CreateAsync(identityUser, model.Password);
            var assignRole = await _userManager.AddToRoleAsync(identityUser, "ADMIN");
类别:

    public class CreateUser:IdentityUser
{
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
    public string OrganizationName { get; set; }
    public string Address { get; set; }
    public string Address2 { get; set; }

    public string TenantId { get; set; }
    public bool IsAdmin { get; set; }
}
DbContext:

  public class ApplicationDBContext:IdentityDbContext<IdentityUser>
{

    public ApplicationDBContext(DbContextOptions options) : base(options)
    {


    }

}
public类ApplicationDBContext:IdentityDbContext
{
公共应用程序DBContext(DbContextOptions选项):基本(选项)
{
}
}
启动

            //Configure Entity Frameworkcore with SQL Server
        services.AddDbContext<ApplicationDBContext>(options =>
        {
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
        });
//使用SQL Server配置实体Frameworkcore
services.AddDbContext(选项=>
{
options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”);
});

如果此处缺少任何内容,则仅更新原始字段,而不插入添加的字段值。

此处应该是CreateUser:

public class ApplicationDBContext : IdentityDbContext<CreateUser>
{

    public ApplicationDBContext(DbContextOptions options) : base(options)
    {

    }

}
public类ApplicationDBContext:IdentityDbContext
{
公共应用程序DBContext(DbContextOptions选项):基本(选项)
{
}
}
Startup.cs:

services.AddIdentity<CreateUser, IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders()
    .AddDefaultUI();
services.AddIdentity()

.AddEntityFrameworkStores文档。

您应该在启动配置服务中将IdentityUser替换为CreateUser,在依赖项注入userManager时也使用此CreateUser。更改为以下内容时显示错误:System.InvalidOperationException:无法为“IdentityUser”创建数据库集,因为上下文的模型中不包含此类型
public class HomeController : Controller
{
    private readonly UserManager<CreateUser> _userManager;

    public HomeController(UserManager<CreateUser> userManager)
    {
        _userManager = userManager;
    }

    //...

}