问题
I have two entities: Municipality and RoadSemgents. Municipality is parent and RoadSegments is a child table. I need to have two foreign Keys in RoadSegments from the same table (Municipality).
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
}
How do I manage this situation? I have read some posts here for foreign keys to multiple tables but none worked for me.
来源:https://stackoverflow.com/questions/11862347/two-foreign-keys-in-entity-framework-for-same-table