views:

281

answers:

1

My application obtains transient objects.

MyClass
  Id
  Name
  OtherData

Mapping is like Id is identifier and Name has unique constraint in database. The transient object has no Id yet of course, but has fulfilled Name property and all other properties. So I can write a criteria to get the entity from database based on that unique field.

How can I easily set other data of the entity by values from transient object to update the entity?

Suppose the class from which the transient and entity objects are created has complex structure and contains other classes or collections of other classes. Suppose also that there are lot of such types in the system which has unique field and should be processed in the same way.

It seems I have to write some recursive routine and via reflection set the values :-( Or is such routine already implemented? Or did I misunderstand something?

+1  A: 

AutoMapper should do the job for you.

Dmytrii Nagirniak
I just tested AutoMapper for this case and it works perfectly, thanks guys!
Petr Felzmann