다른 사용자 데이터를 다른 테이블에 추가 한 다음 AspNetUser (ID 프레임 워크)를 추가 할 수있는 솔루션을 얻으려고합니다. 사용자가 등록하고 로그인 할 때 한 번만이 새 테이블에서 데이터를 검색하려고합니다. 그래서 저는 ApplicationUser와 1 : 1 관계를 맺고 있습니다.사용자 정의 Db가있는 통합 ID 프레임
public class ApplicationUser : IdentityUser
{
//[ForeignKey("User")]
public Guid UserId { get; set; }
[Required]
public User User { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class User
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UserId { get; set; }
public DateTime BirthDate { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public ApplicationUser AspNetUser { get; set; }
}
그리고 2 DB 컨텍스트가
public class MainDbContext: DbContext
{
public DbSet<Project> Projects { get; set; }
public DbSet<ProjectType> ProjectTypes { get; set; }
public DbSet<User> Users { get; set; }
public MainDbContext()
:base("MainDb")
{
}
}
그리고이 하나가 신원 프레임 워크의 내 상황입니다 있습니다.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("MainDb", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
왜 두 개의 데이터베이스가 필요합니까? 'MainDbContext'가'IdentityDbContext'를 상속받을 수 없습니까? 아는 한 DbContext의 객체에 같은 컨텍스트가 아닌 객체에 대한 탐색 속성을 만들 수 없습니다. – Alisson
하나의 데이터베이스 만 있지만 두 개의 컨텍스트가 있습니다. 어떻게 작동하게 할 수 있습니까? ID 프레임 워크와 함께 작동하는 db에 사용자 정의 테이블을 추가해야합니다. 내가 상속받을 수있는 방법을 설명해 주시겠습니까? 그러면 db가 ID 프레임 워크 테이블을 만들 때 내 사용자 정의 테이블도 생성됩니다. – Letoir
'ApplicationDbContext'와 마찬가지로, 제대로 대답 할 것입니다. – Alisson