开发者

NHibernate: set entity from transient object based on unique field

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 ge开发者_开发问答t 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?


AutoMapper should do the job for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜