![](/img/trans.png)
[英]Identity 3.0 - How to use AspNetUsers ID as Foreign Key in a Tiered Application
[英]How to use identity aspnetusers
我之前提了一个问题,但我认为我的提问不正确。
在我的asp.net mvc应用程序中,我使用aspnetusers进行登录和注册。
如果我有另一个用于雇员的模型,其中包含他们的信息,那么我该如何连接这两个模型,以便当用户登录时,它会从雇员表中获取要使用的信息。 我使用sql server创建了Employees Model,并使用了ado.net实体数据模型在Visual Studio中使用它。
员工模式:
public partial class Employee
{
public int UserID { get; set; }
[Key]
public int EmployeeID { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public System.DateTime StartDate { get; set; }
public int RoleID { get; set; }
public int ShiftID { get; set; }
public int AreaID { get; set; }
public int DisciplineID { get; set; }
public int SiteID { get; set; }
public int ALCategory { get; set; }
public int HoursTaken { get; set; }
public Nullable<int> AwardedLeave { get; set; }
public Nullable<int> TotalHoursThisYear { get; set; }
public int HoursCarriedForward { get; set; }
public Nullable<int> EntitlementRemainingThisYear { get; set; }
public string Comments { get; set; }
public int SickLeaveTaken { get; set; }
public Nullable<int> SickLeaveEntitlement { get; set; }
public Nullable<int> SickLeaveEntitlementRemaining { get; set; }
public int StudyLeaveEntitlement { get; set; }
public int StudyLeaveTaken { get; set; }
public Nullable<int> StudyLeaveRemaining { get; set; }
public int ExamLeaveTaken { get; set; }
public int ForceMajeure { get; set; }
public int BereavementLeaveTaken { get; set; }
public int MaternityLeaveTaken { get; set; }
public int ParentalLeaveTaken { get; set; }
public int AdoptionLeaveTaken { get; set; }
public string ManagerEmail { get; set; }
public string AreaManagerEmail { get; set; }
public virtual Area Area { get; set; }
public virtual Discipline Discipline { get; set; }
public virtual Shift Shift { get; set; }
public virtual Site Site { get; set; }
public virtual Employee Employee1 { get; set; }
public virtual Employee Employee2 { get; set; }
}
和登录模型:
public class LoginViewModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
那我可以把这两个连接起来吗? 我使用数据库优先模型有关系吗? 我可以使用外键通过电子邮件进行连接吗?
例如,我想使用它来过滤员工表,以仅显示与登录用户具有相同siteID的员工。
因此,当用户登录时,我希望他们仅在employee HTML表上看到与自己站点相同的员工。
成功登录后,您将获得AspNetUser的ID。 从Employee表的AspNetUser表中获取列ID的外键引用。 这样可以达到预期的效果。 您只需在员工模型中添加另一件事,如下所述:
public virtual ApplicationUser ApplicationUser { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.