I have an object with many children, grand children etc.... Big and bushy branches.
Let's call it a **SaleEntity **and it is loaded from the DB. It's not new.
I use this to clone it nicely.
public static T CloneEntity<T>(T obj) where T : class, ISerializable
{
using (MemoryStream buffer = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
formatter.Serialize(buffer, obj);
buffer.Position = 0;
return (T)formatter.Deserialize(buffer);
}
}
I need to increment the SaleEntity's PK, SaleEntity.SalePK, by 1 then go to each child collection and update their PK by one and so one down the chain. Then save the SaleEntity back to the DB.
Of course when I increment the SaleEntity.SalePK I loose all its child Collections.
Is there a way to change a PK and have that change flow down to all the children on an object that has been loaded from the DB?
Thanks,
Ian