Databind Parent/Child relation with Mysql
Posted
by e2k
on Stack Overflow
See other posts from Stack Overflow
or by e2k
Published on 2010-03-15T20:17:30Z
Indexed on
2010/03/15
20:19 UTC
Read the original article
Hit count: 364
What is the best way to databind parent/child relations? Lets say I have two simple objects:
Parent with the following properties, ParentId, Name and Childs and Child with the following properties, ChildId, Name and Parent.
I want to write a repository using MySql for this but is failing when I bind both Childs and Parent properties, I have only been able to bind either the Childs property of parent or the Parent property och Child or else I would get a infinite loop. Thinking of it the preferable solution would be to only bind this properties when requested.
If I use Linq to sql i would be able to write Parent.Childs[0].Parent.Name but how should I accomplish this with my own repository and with MySql, could anyone point me in the right direction? Looking at the Linq 2 sql generated classes they use EntitySet<Child> and EntityRef<Parent> could this be used with Mysql?
I had a thought of using my IChildRepository in the Parent object and let the Public IEnumerable Childs databind the childs but it seems not right?
Best regards E2k
© Stack Overflow or respective owner