CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Copy / Duplicate child BO

rated by 0 users
Answered (Verified) This post has 1 verified answer | 2 Replies | 1 Follower

Not Ranked
13 Posts
ksavoie posted on Thu, May 19 2011 8:24 AM

I've been ask by my client to add a "duplicate" function to my windows form application in VB.NET 2005, using CSLA 2.

I'm looked into the copy of the object.  I tried to use the following code, but it's not doing what I need. 

Public Shared Function NewCost(ByVal oldCost As Customer) as Cost
   Return CType(DataPortal.Create(New CopyCriteria(oldCost)), Cost)
End Function

<Serializable()>
Private Class CopyCriteria
   Public OldCost as Cost
   Public Sub New(ByVal oldCostas Cost)
        Me.OldCost = oldCost
   End Sub
End Class

I have a one Contract, with a list of Cost.  I want to be able to duplicate the Contract Information and the first Cost, so CostID = 0.

How would I duplicate/copy only the information of the CostID = 0?  I tried to find a solution online, but without success.

Can anybody help me with this one?  Examples of code would be great.

 

Answered (Verified) Verified Answer

Not Ranked
13 Posts
Answered (Verified) ksavoie replied on Fri, May 20 2011 11:32 AM
Verified by ksavoie

thanks Andy,

I'll try your second option.

All Replies

Top 10 Contributor
3,922 Posts
Answered (Not Verified) Andy replied on Thu, May 19 2011 7:47 PM
Suggested by Andy

Are you trying to duplicate the data first, then return an instance, or duplicate an instance the user is currently looking at?

If its the former, you probably want to go with a command object that simply copies the rows in the database, and returns the new objects id.

If you're after the latter, create a duplicate instance method.  The method should be fairly straight forward, the first thing it will do is Clone itself, then you'll need to set all the primary key values in your objects to null or empty or whatever.  Ensure each item in the graph calls MarkNew, then you may want to run rules on all instances again.

At that point you can present the "new" object to the user, allowing them to edit and then save the new object.

Not Ranked
13 Posts
Answered (Verified) ksavoie replied on Fri, May 20 2011 11:32 AM
Verified by ksavoie

thanks Andy,

I'll try your second option.

Page 1 of 1 (3 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems