Entity Framework Self Join & Child Objects
Using Entity Framework in .net 4.0, how do you set up an entity for the object below?
I have an item that people can comment on and then people can comment on comments and so on
E开发者_Go百科x:
Item -Comment --Comment --Comment ---Comment -Comment -Comment --Comment
My current table structure in sql:
Comments
ID (int) ParentCommentID (int) ProductID (string) Title Text
Thanks
A good idea would be to check out the Stack Overflow Creative Commons Data Dump.
They have a similar setup for post/comments, so you can see how they setup their schema. Hanselman also has a blog post on a OData service for it here, so you can check out his EDMX.
Your on the right track though:
- Item 1..* Comments
- Comment 1..* Comments
You'll need to setup ParentCommentID as self-referencing FK, then when you import that into your EDMX Entity Framework should model it correctly. You might need to rename the nabigational property to something more meaninful.
Good luck!
精彩评论