I am trying to represent a graph with typed edges in an entity-framework code-first model. I am having quite a difficulty understanding how to set up the relationships correctly. I am calling the nodes in my graph ‘Items’ and the edges ‘Relationships’ Here is what I have:
public class Item : Learnable
{
public Boolean IsBeginningItem { get; set; }
public virtual List<Relationship> RelationshipsLeft { get; set; }
public virtual List<Relationship> RelationshipsRight { get; set; }
}
–
public class Relationship : Learnable
{
public Boolean IsPrerequisiteRelationship { get; set; }
public virtual RelationshipType RelationshipType { get; set; }
public int ItemLeftID { get; set; }
[ForeignKey("ItemLeftID")]
public virtual Item ItemLeft { get; set; }
public int ItemRightID { get; set; }
[ForeignKey("ItemRightID")]
public virtual Item ItemRight { get; set; }
}
And here is what I am getting:

How can I get the RelationshipsRight property of Item to correspond to the ItemLeft property of Relationship AND the RelationshipsLeft property of Item to correspond to the ItemRight property of Relationship?
Oh… and I guess I should explain that this is supposed to be a directed graph that I can navigate bidirectionally. 🙂
You can use the
[InverseProperty]attribute to bind the correct pairs of navigation properties together: