Eduardo
Eduardo

Reputation: 709

Entity Framework many to many with parent/child table

I am trying to develop a query that seeks parents in a table where the fields are parent and child, using lambda syntax or query syntax.

My model is basically

Entities
EntityID
Name
Age
EntityType

EntitiesRelation
EntityParentID [PK, FK, EntityID]
EntityChildID [PK, FK, EntityID]

I know I cannot access the EntitiesRelation table directly (because it is a Join table). I have other queries with join tables, but this case, I couldn't resolve until now.

Upvotes: 0

Views: 585

Answers (1)

Gusman
Gusman

Reputation: 15151

You should have two navigation properties, Entities1 and Entities11 as you stated, one belongs to the relationship as parent and the other as child.

Look at the designer to which one corresponds each and name them "Parent" and "Children" and you are ready.

Upvotes: 1

Related Questions