asp.net-core - ASP.Net Core API:如何将用户身份链接到联系人
问题描述
我正在开发一个利用 ASP.Net Core 在 SQL 中的用户/角色身份表的应用程序。
由于我现在正在构建的应用程序的性质,公开注册是不可能的。我要构建的内容需要应用程序的管理员首先将新员工作为联系人添加到应用程序中。保存他们的联系信息后,他们将单击一个按钮将该联系人设置为用户。
您推荐什么方法来扩展身份框架或将 AspNetUsers 与我的联系人表链接以实现此目标。我确信我会经常从这个设置的双方查询信息,这是我提出这个问题的主要原因。
非常感谢您的帮助。如果我可以提供更多详细信息,请告诉我。
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; }
}
解决方案
AContact
可以在没有 的情况下存在,User
但 aUser
不能在没有 的情况下存在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; }
}
推荐阅读
- angular - Angular:如何根据验证器正确查找和添加类到角度元素
- javascript - 向 Vue 实例的销毁钩子添加回调
- visual-studio - 无法在具有 Anaconda 环境的 VS Code 中为 Plotly Dash 运行本地服务器
- python - 使用 librosa 理解 STFT
- javascript - 无法在谷歌应用脚本表中使用类方法
- json - 如何使用 react-router-dom 创建动态路由?
- python-3.x - 尝试在框架上添加滚动条时出现问题
- javascript - Orderby 不使用 Microsoft Graph API
- ios - 如何使用硬件键盘在 iOS 模拟器中键入 @?
- logistic-regression - 如何估计累积链接混合模型中的整体截距?