Best Practice For Copy Operation

Best Practice For Copy Operation

Old forum URL: forums.lhotka.net/forums/t/4447.aspx


DamReev posted on Monday, March 03, 2008

I'm trying to copy objects which have children, but I'm running into some issues. I need to be able to do a deep copy and rollback EditLevels without rollingback changes.

I have the following:

class Activity:BusinessBase<Activity>{
 public int ActivityId{get{...}set{...}}
 public ActivityType ActivityType{get{...}set{...}}
 public ParticipantList Participants {get{...} set{...}}
 public ActivityNote Note {get{...}set{...}}
 
 public TActivity As<TActivity>() where TActivity:Activity{
  TActivity activity = ActivityFactory.NewActivity<TActivity>();
  Csla.Data.DataMapper.Map(this, activity, true, "ActivityType");
  activity._activityId = this._activityId;
  if (this.IsNew) activity.MakeNew();
  else activity.MarkOld();
  if (this.IsDirty) activity.MarkDirty();
  if (this.IsChild) activity.MarkAsChild();
  if (this.IsDeleted) activity.MarkDeleted();
  return activity;
 }
}

class Meeting:Activity{
 public MeetingType MeetingType{get{...}set{...}}
 public string Location{get{...}set{...}}
}

class Call:Activity{
 public CallType CallType{get{...}set{...}}
}

I would like to call the As<TActivity>() method to create a new Call which is pretty much a clone of the Meeting and I want to databind this Call to my UI (with a BindingSource) in place of the Meeting object it was copied from. However when I try to databind I run into issues with edit levels. Is there a way for me to reset the editlevels of all the child objects (Note and ParticipantsList, which contains Participant child objects) that have been "cloned"? I want all objects to be in the same state they would be in as if I had populated the object from the database or I had just created a brand new object.

Copyright (c) Marimer LLC