我正在开发一个利用ASP中的ASP.Net Core的用户/角色身份表的应用程序。
由于我正在建立的应用程序的性质,公共注册是不可能的。我要构建的内容需要管理员首先将新员工作为联系人添加到应用程序中。保存联系信息后,他们会单击按钮将该联系人设置为用户。
您建议的方法是扩展身份框架或将AspNetUsers与我的Contacts表链接以实现此目标。我相信我会经常从这个设置的双方查询信息,这是我提出这个问题的主要原因。
非常感谢您的帮助。如果我能提供更多详细信息,请告诉我。
public class ApplicationUser : IdentityUser
{
public virtual ICollection<Contact> Contacts { get; set; }
}
public class Contact
{
[Key]
public int Id { get; set; }
public string IdentityUser { get; set; }
[ForeignKey("IdentityUser")]
public virtual ICollection<ApplicationUser> AppUser { get; set; }
}
没有Contact
可以存在User
,但没有User
就不能存在Contact
。简单的一对一关系:
public class User : IdentityUser<int>
{
int ContactId { get; set; }
Contact Contact { get; set; }
}
public class Contact
{
int? UserId { get; set; }
User User { get; set; }
}