I have a table called Area, that stores areas in a hierarchical manner. There is an Id and a ParentId column in the table. The ParentId is linked with a foreign key to the table’s Id column.
When I generate the EDM, I get two navigation properties, Area1 and Area2. How am I supposed to get back a tree structure of my areas, and navigate in the tree using LINQ to entities?
I may be asking the wrong question entirely, please bear with me. 🙂
Its the right question. When you generate based of the database schema, LINQ autonames the child and parents.
I’d check the designer.cs for your model, but most likely Area1 is the child and Area2 is the Parent. Or its vice versa.
If you want to get all children of a current Area instance:
If you want the parent:
I don’t know if you can rename the child and parent, it should be possible. Just haven’t dug much into that.