我目前有一個使用身份的專案,個人用戶可以訪問他們自己的資源(由應用程式用戶 ID 鏈接的子資料庫表)。我希望每個注冊(管理員)的用戶都能夠邀請新用戶加入他們的“組”,并且所有人都共享相同的資源。
我正在考慮實作類似于當前“角色”和“用戶角色”表的“組”和“用戶組”表。以下代碼看起來可以實作這一目標嗎?
public class ApplicationUser : IdentityUser
{
[MaxLength(30)]
public string FirstName { get; set; }
[MaxLength(30)]
public string LastName { get; set; }
[MaxLength(100)]
public string Company { get; set; }
[MaxLength(30)]
public string Telephone { get; set; }
[MaxLength(15)]
public string Postcode { get; set; }
public DateTime Created { get; set; } = DateTime.UtcNow;
public DateTime PasswordResetTime { get; set; } = DateTime.UtcNow;
public bool PasswordReset { get; set; } = false;
public virtual ICollection<GSMSite> GSMSites { get; set; }
}
public class UserGroups
{
public virtual ApplicationUser ApplicationUser { get; set; }
public virtual Groups Groups { get; set; }
}
public class Groups
{
public Guid Id { get; set; }
[MaxLength(30)]
public string Name { get; set; }
}
uj5u.com熱心網友回復:
您正在嘗試實作多對多關系。首先按照慣例你應該用單數形式命名類:
- 群組- >用戶組
- 組->組
您還應該將ICollection<UserGroup>放在 AplicationUser 和 Group 中:
public virtual ICollection<UserGroup> UserGroups
并更改用戶組到:
public class UserGroup
{
public Guid ApplicationUserId { get; set;}
public virtual ApplicationUser ApplicationUser { get; set; }
public Guid GroupId { get; set; }
public virtual Groups Groups { get; set; }
}
然后您正在談論的資源應該鏈接到Group而不是ApplicationUser。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/331413.html
上一篇:GS1條碼決議——好像沒有分隔符
