Mahesh Velaga
Mahesh Velaga

Reputation: 21991

How to do deep copy of NHibernate Objects?

I am trying to do a deep copy of a NHibernate object (proxy wrapper). I want to do a copy of lazily loaded things also, except the Id of each inner object of the parent object, as it should be generated when I save the new object which is the result of deep copy.

I have tried to use serialization and also tried using AutoMapper (I know, its not meant for this, just gave it a try). Both didn't yield what I want.

I am thinking of manually copying each and every property as the last option, if there is no better way to do it.

I found this question, but it didn't address what I wanted, considering I was reluctant to do the copy manually.

Upvotes: 1

Views: 2078

Answers (2)

Mahesh Velaga
Mahesh Velaga

Reputation: 21991

We had to have more customizations done as we went on cloning the classes.

So, in our case manual clone was the way to go (even though I was hoping for a better solution).

Upvotes: 1

andyp
andyp

Reputation: 6269

we're using Copyable to clone objects (deep clones). Here you can find an article describing Copyable. It provides extension methods (for 'object') that allow to clone object graphs and generally works very well for us. HTH.

Upvotes: 0

Related Questions