无法在 Aspnetuser 中添加其他字段 table
Unable to Add Additional Fields in Aspnetuser table
我创建了自定义字段并尝试将自定义字段插入到 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");
Class:
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"));
});
这里有什么遗漏吗,只有原始字段得到更新,而没有插入添加的字段值。
这里应该是CreateUser:
public class ApplicationDBContext : IdentityDbContext<CreateUser>
{
public ApplicationDBContext(DbContextOptions options) : base(options)
{
}
}
Startup.cs:
services.AddIdentity<CreateUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
依赖注入:
public class HomeController : Controller
{
private readonly UserManager<CreateUser> _userManager;
public HomeController(UserManager<CreateUser> userManager)
{
_userManager = userManager;
}
//...
}
自定义的详细步骤可以在 Customize the model 文档中找到。
我创建了自定义字段并尝试将自定义字段插入到 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");
Class:
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"));
});
这里有什么遗漏吗,只有原始字段得到更新,而没有插入添加的字段值。
这里应该是CreateUser:
public class ApplicationDBContext : IdentityDbContext<CreateUser>
{
public ApplicationDBContext(DbContextOptions options) : base(options)
{
}
}
Startup.cs:
services.AddIdentity<CreateUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
依赖注入:
public class HomeController : Controller
{
private readonly UserManager<CreateUser> _userManager;
public HomeController(UserManager<CreateUser> userManager)
{
_userManager = userManager;
}
//...
}
自定义的详细步骤可以在 Customize the model 文档中找到。