ASP.Net Core API:如何将用户身份链接到联系人

问题描述 投票:0回答:1

我正在开发一个利用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; }
}
asp.net-core asp.net-identity
1个回答
1
投票

没有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; }
}
© www.soinside.com 2019 - 2024. All rights reserved.