Search code examples
c#nhibernateobjectdeep-copy

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.


Solution

  • 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).