2

I am trying to create data model for a graph with Node and Edge. If Edge does not contain any property I can simply create many-to-many association from a Node to itself. However I want to store some properties on the Edge e.g. Distance. I tried to create another entity but didn't find a way to declare the relationship between Edge and Node. Is it possible in Model First? How?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
NS.X.
  • 2,072
  • 5
  • 28
  • 55

1 Answers1

7

You must create two one-to-many associations from Node to Edge to model self referencing many-to-many relation with mapped junction table. In terms of graph theory EF models creates oriented graph so it differs between edge from A to B and from B to A.

You will start with your two entities and their properties:

enter image description here

You will drag the first Association from Toolbox. Start at Node and drag association to Edge - it will create one-to-many relation between Node and Edge. Configure properties of created navigation for "Outgoing" edges:

enter image description here

You will drag the second Association in the same way and configure its properties for "Incoming" edges:

enter image description here

After generating a database from this model you will get this table structure:

enter image description here

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670