如何指定从实体X到同一目标实体Y的两个导航属性? [英] How to specify two navigation properties from entity X to the same target entity, Y?

查看:59
本文介绍了如何指定从实体X到同一目标实体Y的两个导航属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有一个讲师课:

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

    public virtual ICollection<Course> Courses { get; set; }

    public virtual ICollection<Course> CoInstructingCourses { get; set; }
}

此处, InstructorTypesEnum 具有两个值:讲师和共同讲师。因此,两个导航属性 Courses CoInstructingCourses 应该返回那些不同的课程。

Here, InstructorTypesEnum has two values: instructor and co-instructor. So the two navigation properties Courses and CoInstructingCourses are supposed to return those different courses.

当然我也很难在 Course

    public Guid InstructorId { get; set; }

    public virtual Instructor Instructor { get; set; }

    public virtual ICollection<Instructor> Coinstructors { get; set; }

正确的做法是什么?

推荐答案

您可以使用 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; }
}

这篇关于如何指定从实体X到同一目标实体Y的两个导航属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆