Greg
Greg

Reputation: 34818

Entity Framework - How do create an association to/from the same entity?

In Entity Framework (VS2010) how do I create an association to/from the same table? (a many-to-many is what I want)

Background - I was expecting under the bonnet a NODE and RELATIONSHIP table, where the latter has a parent_node_id and a child_node_id (i.e. pointing back to the NODE id column). I can't seem to get the designer to add it...

Upvotes: 0

Views: 534

Answers (1)

Ian Mercer
Ian Mercer

Reputation: 39297

Model first: create entity, right click: add association, select same Entity, mark it Many to many on both ends.

Database first: create two tables: Node and Edge, Edge contains two Node references. (Using appropriate PK, FK's).

Upvotes: 2

Related Questions