0

我有一个这样的实体:

public class Course
{
    public int Id { get; set; }
    public string Name { get; set; } 

    public virtual ICollection<Course> Prerequisites { get; set; }
    public virtual ICollection<Course> Equivalents { get; set; }

    public Course()
    {
        Prerequisites = new HashSet<Course>();
        Equivalents = new HashSet<Course>();
    }
}

我想为“先决条件”和“等效项”创建不同的表。我该如何配置它?

4

1 回答 1

1

这可能会有所帮助

public class Course
{

    public int Id { get; set; }
    public String Name { get; set; }

    [InverseProperty("PrerequisiteFor")]
    public virtual ICollection<Course> Prerequisites { get; set; }
    [InverseProperty("EquivalentTo")]
    public virtual ICollection<Course> Equivalents { get; set; }
    [InverseProperty("Equivalents")]
    public virtual ICollection<Course> EquivalentTo { get; set; }
    [InverseProperty("Prerequisites")]
    public virtual ICollection<Course> PrerequisiteFor { get; set; }

    public Course()
    {
        Prerequisites = new HashSet<Course>();
        Equivalents = new HashSet<Course>();
        PrerequisiteFor = new HashSet<Course>();
        EquivalentTo = new HashSet<Course>();

    }
}
于 2014-03-08T10:28:54.583 回答