How to duplicate an Entity and save it to new record

Posts   
 
    
phongbui
User
Posts: 2
Joined: 14-Mar-2008
# Posted on: 14-Mar-2008 12:18:51   

Here is my data model:

SubmissionEntity +SubmissionCustomerEntityCollection +SubmissionDsgroupEntityCollection

Each SubmissionCustomerEntity contains + CustomerEntity + LoanEntityCollection + and so on...

Each SubmissionDsgroupEntity contains + DsgroupEntity + SumaryTableEntity

The application have the features to copy data from one SubmissionEntity to another SubmissionEntity. Let's say copy data from submissionA to submissionB.

I loaded all data from submissionA and now it's available to access at - submissionA.SubmissionCustomers - submissionA.SubmissionDsgroups

I tried to clone (using the source from http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7568 ) each items in two above collections and add them to the submissionB. However, when I save the submissionB, the entire data that belongs to submissionA is disappeared. They are actually moved to the submissionB.

It would be nice if someone can give me a suggest how to do it, or even work around to get it done? Is there anyway to save an existing Entity to new records?

Thanks, Phong

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 14-Mar-2008 15:59:26   

Please post your code and the runtime library version used.

Also you can clone a graph using serialization / deserialization as described in the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1834 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12424

TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 25-Mar-2008 19:47:09   

Walaa wrote:

Please post your code and the runtime library version used.

Also you can clone a graph using serialization / deserialization as described in the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1834 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12424

Walaa,

I'm having this same problem. I have runtime 2.5.8.122 The code I'm using is specified in the thread you refer to


         // fetch data in myCustomer entity. (a graph). 
         // BinaryFormatter is the formatter for remoting, part of .NET
         BinaryFormatter formatter = new BinaryFormatter();
         MemoryStream stream = new MemoryStream();
         formatter.Serialize(stream, oldDP);
         // seek the stream back to the beginning.
         stream.Seek(0, SeekOrigin.Begin);

         // deserialize the data back into a new instance (and all the related entities)
         DataProfileEntity clone = (DataProfileEntity)formatter.Deserialize(stream);
         clone.Description = "copy of " + oldDP.Description;
         clone.IsNew = true;
         clone.Fields.IsDirty = true;

Kind regards, TomV

TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 25-Mar-2008 20:22:05   

Never mind, I was able to clone my object via this thread:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7568

The only thing I had to do was to reset the new object's PK


         newDP.Fields[0].ForcedCurrentValueWrite(null);  //Reset the PK of the dataprofile