Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone objects in NHibernate?

How to implement objects (entities) cloning in NHibernate? Each entity class has such properties:

public virtual IList<Club> Clubs { get; set; }

Also, the entity class inherits BaseObject. I tried to implement the solution using XML serialization, but it's not possible to serialize interfaces.

Thank you for your answers!

like image 915
akrisanov Avatar asked Mar 11 '10 17:03

akrisanov


2 Answers

AutoMapper http://automapper.codeplex.com/ solves my problem. For example, it's possible to clone a business object in the next way:

Mapper.CreateMap<Transaction, Transaction>();
var newtransact = new Transaction();
Mapper.Map(transact, newtransact);
like image 54
akrisanov Avatar answered Nov 17 '22 15:11

akrisanov


Use DTOs.

like image 27
Jim G. Avatar answered Nov 17 '22 14:11

Jim G.