How to specify two navigation properties from entity X to the same target entity, Y?

前端 未结 2 1524
青春惊慌失措
青春惊慌失措 2021-01-26 06:09

Consider that I have an Instructor class:

public class Instructor
{
    public InstructorTypesEnum Type { get; set; }

    public virtual ICollectio         


        
相关标签:
2条回答
  • 2021-01-26 06:44

    What's more - you shouldn't use GUID as entity ID. It hurts performance.

    public Guid InstructorId { get; set; }
    

    Try to replace it with for example int.

    0 讨论(0)
  • 2021-01-26 06:50

    You can use the InversePropertyAttribute

    On your model, I think it would be (not verified):

    public class Instructor
    {
      public InstructorTypesEnum Type { get; set; }
    
      [InverseProperty("Instructors")]
      public virtual ICollection<Course> Courses { get; set; }
    
      [InverseProperty("Coinstructors")]
      public virtual ICollection<Course> CoInstructingCourses { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题