【问题标题】:Naming Parent Entity Relations if multiple relations with a Table - Entity Data Model - ADO.Net如果与表有多个关系,则命名父实体关系 - 实体数据模型 - ADO.Net
【发布时间】:2021-01-20 08:57:45
【问题描述】:

如果一个表与其他表有多个关系。 例如员工和任命表。 约会表有 2 个字段作为 Employee 表的外键。 1 个密钥用于约会,其他密钥用于添加该记录的员工。

现在,在代码中,当我们通过 Appointment 对象访问 Employee 时,它​​会提供像 Appointment.Employee 和 Appointment.Employee1 这样的引用

有没有办法可以将 Employee 和 Employee1 重命名为有意义的关系?

提前致谢,

【问题讨论】:

    标签: c# entity-framework ado.net edmx


    【解决方案1】:

    您可以随意命名导航属性

     public class Appointment
        {
            ...other props
            public int EmployeeId { get; set; }
            public virtual Employee Employee { get; set; }
    
            public int CreatedByEmployeeId { get; set; }
            public virtual Employee CreatedByEmployee { get; set; }
        }
    

    因此,您可以这样称呼它:Appointment.Employee 或 Appointment.CreatedByEmployee

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多