如果与表存在多个关系,则命名父实体关系 - 实体数据模型 - ADO.Net

问题描述

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

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

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

提前致谢,

解决方法

您可以随意命名导航属性

 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