I am trying to serialize and graph EF 4.0 objects in XML for transmission through the WCF service. I used to do this with DTO / POCO (usually for JSON serialization). In this case, since I only perform XML serialization, it seemed to me that I could just serialize entity objects, but I ran into this puzzle:
If I do not detach the object, serialization throws an error that the object context has been deleted (because it has at this point that this is expected).
If I detach an object, all related objects loaded in the navigation properties will be deleted.
My assumption was that if I enumerated any related objects, then separated the object from the context, I would still have these relationships available for serialization.
So my question is: is there any way to serialize an entity object and save any loaded navigation properties / collections?
Thank...
source
share