【发布时间】:2020-10-06 06:45:01
【问题描述】:
我创建了一个自定义字段并尝试在 aspnetusers 表中插入自定义字段,但未插入其他字段数据。下面是我试过的代码:
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; }
}
数据库上下文:
public class ApplicationDBContext:IdentityDbContext<IdentityUser>
{
public ApplicationDBContext(DbContextOptions options) : base(options)
{
}
}
启动
//Configure Entity Frameworkcore with SQL Server
services.AddDbContext<ApplicationDBContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
});
这里有什么遗漏吗,只有原始字段被更新,而添加的字段值没有被插入。
【问题讨论】:
标签: asp.net-core ef-code-first asp.net-identity