我有两个实体:Municipality和RoadSemgents。市政当局是父母,而RoadSegments是儿童表。我需要在同一张桌子(市政府)的RoadSegments中有两个外键。
public class Municipality
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
public class RoadSegments
{
[Key]
public int ID { get; set; }
//ForeignKeys
public int CodeMunicipalityLeft_ID { get; set; }
public int CodeMunicipalityRight_ID { get; set; }
[ForeignKey("CodeMunicipalityLeft_ID ")]
public Municipality CodeMunicipalityLeft { get; set; } // LOOK HERE
[ForeignKey("CodeMunicipalityRight_ID ")]
public Municipality CodeMunicipalityRight { get; set; } // AND HERE
}
我该如何处理这种情况?我在这里读了一些关于多个表的外键的帖子,但没有一个对我有用。