Currently the cloning is based on setting OldPrimaryKey
to each newly cloned mode node item. It’s a bit hidden there, and it’s not persisted. The mapping is used in updateReferences()
. If someone or something invalidates model cache in between calling Clone()
and UpdateReferences()
, it breaks the functionality, because model is loaded from the disk without OldPrimaryKey
set. Moreover, the complexity of UpdateReferences()
operation is n^2.
refactoring:
Clone()
would return Dictionary<Guid,Guid> primaryKeyMapping
having oldPrimaryKey
as a key and newPrimaryKey
as a value. PrimaryKeyMapping
would be passed into UpdateReferences()
. Complexity should drop to nlog(n).