Aspnetuser 테이블에 추가 필드를 추가 할 수 없습니다.
Oct 06 2020
사용자 정의 필드를 만들고 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; }
}
DbContext :
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"));
});
여기에 누락 된 항목이 있습니까? 추가 된 필드 값이 삽입되지 않는 동안 원래 필드 만 업데이트됩니다.
답변
1 mj1313 Oct 06 2020 at 06:59
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;
}
//...
}
사용자 정의 할 세부 단계 는 모델 문서 사용자 정의에서 찾을 수 있습니다 .