public class Account { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int AccountID { get; set; } public string LoginName { get; set; } public string Password { get; set; } public string SecurityStamp { get; set; } /// <summary> /// 默認: 1 可以登錄 0 已刪除(不能登陸) /// </summary> public int Status { get; set; } public virtual AccountInfo AccountInfo { get; set; } [ForeignKey("Role")] public int RoleID { get; set; } public virtual Role Role { get; set; } public virtual ICollection<AccountModule> AccountModules { get; set; } }
public class AccountInfo { [Key] [ForeignKey("Account")] public int AccountID { get; set; } public virtual Account Account { get; set; } [Required] [StringLength(100)] public string Email { get; set; } [StringLength(100)] public string Mobile { get; set; } [StringLength(100)] public string Telephone { get; set; } [Required] [StringLength(100)] public string Name { get; set; } [StringLength(100)] public string QQNumber { get; set; } }
public class AccountModule { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int AccountModuleID { get; set; } [ForeignKey("Account")] public int AccountID { get; set; } public virtual Account Account { get; set; } [ForeignKey("Module")] public int ModuleID { get; set; } public virtual Module Module { get; set; } }
public class Role { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int RoleID { get; set; } public string RoleName { get; set; } }
看了上面幾個Model相信大家已經知道了吧。
1對1,就是Account 對於 AccountInfo
多對一 就是Account對於Role
多對多 就是Account對於Module
相信大家應該已經理解了