我正在尝试在我的AspNetUser(ApplicationUser类)表和Employee表之间创建一对一的关系。
问题是:
我尝试了什么:
以下是我希望实施的示例:
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public ApplicationUser()
: base()
{
PreviousUserPasswords = new List<PreviousPassword>();
}
public virtual IList<PreviousPassword> PreviousUserPasswords { get; set; }
public virtual Employee Employee { get; set; }
}
[Table("EMPLOYEE")]
public class Employee
{
[Key, Column("ID")]
public int Id { get; set; }
[Column("ID_IDIOM")]
public int IdIdiom { get; set; }
[Column("USER_LOGIN")]
[Required]
[StringLength(50)]
public string UserName { get; set; }
[Column("NAME")]
[Required]
[StringLength(100)]
public string Name { get; set; }
[Column("EMAIL")]
[Required]
[StringLength(100)]
public string Email { get; set; }
[Column("ACTIVE")]
public bool Active { get; set; }
[Column("EMPLOYEE_TYPE")]
public short EmployeeType { get; set; }
[Column("SHOW_TUTORIAL")]
public bool ShowTutorial { get; set; }
public ApplicationUser User { get; set; }
}
任何想法都会有所帮助。
PS:抱歉我的英文不好。
答案 0 :(得分:3)
如果您的应用程序上下文继承自IdentityDbContext,则可以使用流畅的api进行配置:
modelBuilder.Entity<Employee>()
.HasRequired(e => e.User)
.WithRequiredDependent(u => u.Employee);
请参阅https://msdn.microsoft.com/en-us/data/jj591620.aspx?f=255&MSPPError=-2147217396#RequiredToRequired