problem with XML serialisation

Posts   
 
    
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 04-Dec-2006 19:30:46   

Hi,

I am doing an import/export system in order to transfer entities tree from a data base to an other.

First, I retrive entities to export with a fetchEntity with a prefetchPath, then i serialise the top entity into a xml file.

Then, in the destination server, I modify the xml file to make all entities as new. I do the following operations to all entities :

  • Set IsNew to True
  • Set IsDirty to True
  • Set all field IsChanged to True
  • Remove all DbValue nodes
  • Set all PK and FK to 0

then I deserialise the xml in an entity and I save it.

And my problem comes there : when the prefetchpath used above contains 2 path to the same entity, I noticed this entity is duplicated into the xml (there is NO use of ProcessedObjectReference) and when I save, this entity is twice in the insert queue. For the first, save query is ok, but for the second one, all FK are set to 0 and the save query fails !

Am I doing something wrong ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 04-Dec-2006 20:13:43   

This is caused by the fact that the fetch logic creates one new instance for a loaded entity, if that entity is fetched multiple times.

If you want unique entities, use a Context with the fetch.

Frans Bouma | Lead developer LLBLGen Pro
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 04-Dec-2006 20:51:55   

thanks it works !