Clone List - Question

Oct 14, 2011 at 5:45 PM

Hello,

I am looking for a way to "copy" an object.  I create the new object and use FillClone(newObject) to shallow copy the item.

I then go ahead and create the sub-objects (foreign-keys) for the newly created item.  Here is a snippet from my NHDAL partial class;

ObjectType retval = null;
ObjectTypeCollection collection = new ObjectTypeCollection ();
retval = collection.NewItem();
FillClone(retval);  //copy all of the base information (not linked)
collection.AddItem(retval);

SubTypeCollection atColl = collection.SubDomain.GetCollection<SubTypeCollection>();
foreach (SubType t in this.ObjectType_SubTypeList)
{
         atColl.AddItem((SubType)t.Clone(retval.ID, t.LinkedID));
}

I get the error "This row already belongs to another table".  Obviously this is due to the fact that the underlying data stucture is a dataset.  Generally I would use "ImportRow" to import the new information into the new datarow.  This is not available through the exposed methods of the SubTypeCollection.

Is there something I am missing to accomplish my goal here?  

Any help I can get would be appreciated.

Thanks,

Steve!

Oct 18, 2011 at 4:52 PM

For now I just wrapped each object I needed's "FillClone(item)" method in a public facing FillObject(item).

My code now looks like this:

SubTypeCollection atColl = collection.SubDomain.GetCollection<SubTypeCollection>();
SubType obj;
foreach (SubType t in this.ObjectType_SubTypeList())
{
  obj = t.FillObject(atColl.NewItem());
  obj.LinkedID = t.LinkedID;
  atColl.AddItem(obj);
}

Can I request that the FillClone() method be made public facing in the generated code, or a wrapper placed around it?

Thoughts?

Steve