Traversing an object Tree to the end in EF4

added by ananto
7/17/2012 8:23:09 AM

2 Kicks, 183 Views

Traverse the full tree of the object through their relationship/navigation until it will reach to leaf.


7/17/2012 8:28:59 AM
Maybe I'm not understanding the post, but doesn't it seem silly to go to such lengths to return a list of orders for a given customer? I mean, it looks like your code using recursion, reflection, and generic there some reason you couldn't have done this?
If I've missed something important, I apologize, but your post doesn't seem to really explain why you had to go to such great lengths.

7/17/2012 8:37:15 AM
yes I would like to go into such great length because I want to backup the object Graph
into a backup file and later on it will be attached to database that might be the same database or to another database one with same schema.It will not override existing one if that any data of an object already exist , if not then it will insert the object will related object.
7/17/2012 8:46:57 AM
Thanks for getting back to me. So if you just need to serialize the objects, are the built-in serialization methods not sufficient if you've loaded all related entities using the method in the link I put in my last comment? Here's the MS doc on binary serialization with EF for example:
Could that method work in this scenario if you had the object graph loaded by disabling lazy loading?

(PS: Sorry for not directly replying to your last comment, the comment system is giving me difficulty this morning)

7/17/2012 10:30:06 AM
Thanks for the link and great suggestion. But I am not sure , some days ago I read something :
Because POCO entities do not have the same relationship requirements as objects that inherit from EntityObject, a slightly different process is required to load related objects. For general information about loading related objects, see Loading Related Objects and Loading Related Objects.