zoukankan      html  css  js  c++  java
  • 5.对与表与表之间的关系,efcore是如何处理的

    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

    相信大家应该已经理解了

  • 相关阅读:
    servlet遇到的问题
    servlel出现404问题★ 出现不自动映射 设置XML的问题时候
    c3p0的错误mchange.v2.ser.Indirector
    【转】JSON和JSONP
    性能测试理论
    如何解决包冲突问题
    一方包、二方包、三方包是什么?
    利用selenium webdriver点击alert提示框
    采用Spring管理Bean和依赖注入
    Java加载jar文件并调用jar文件当中有参数和返回值的方法
  • 原文地址:https://www.cnblogs.com/quan01994/p/6002968.html
Copyright © 2011-2022 走看看