ASP.Net 核心 API:如何 link 联系人的用户身份
ASP.Net Core API: How to link User Identity to a Contact
我正在开发一个应用程序,它利用 ASP.Net Core 在 SQL 中的 User/Role 身份 tables。
由于我现在正在构建的应用程序的性质,public 无法注册。我要构建的内容需要应用程序的管理员首先将新员工作为联系人添加到应用程序中。保存他们的联系信息后,他们会单击一个按钮将该联系人设置为用户。
您推荐的方法是什么来扩展身份框架或 link AspNetUsers with my Contacts table 以实现此目标。我确信我会经常从这个设置的两边查询信息,这是我问这个问题的主要原因。
非常感谢您的帮助。如果我可以提供更多详细信息,请告诉我。
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; }
}
我正在开发一个应用程序,它利用 ASP.Net Core 在 SQL 中的 User/Role 身份 tables。
由于我现在正在构建的应用程序的性质,public 无法注册。我要构建的内容需要应用程序的管理员首先将新员工作为联系人添加到应用程序中。保存他们的联系信息后,他们会单击一个按钮将该联系人设置为用户。
您推荐的方法是什么来扩展身份框架或 link AspNetUsers with my Contacts table 以实现此目标。我确信我会经常从这个设置的两边查询信息,这是我问这个问题的主要原因。
非常感谢您的帮助。如果我可以提供更多详细信息,请告诉我。
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; }
}