Perhaps AutoMapper is useful in your case. 2009/6/19 Tyler Burd <[email protected]>
> Hiya, Fabio. > > > > I’m not annoyed to do it by myself, it’s just that when adding properties > to a persistent class the development team has to remember to add those > properties into all of the places the deep copy occurs as well. This is > pretty error prone and non-obvious. Serialization doesn’t do it, because > there are some associations that aren’t supposed to get copied (as they > aren’t part of the aggregate tree). Here is an example: > > > > class UserSettings > > -Id > > -MailingAddress <-set to cascade=all > > -Organization <-set to cascade=none > > > > var newUserSettings = deepCopy(oldUserSettings); > > newUserSettings.MailingAddress.City = “Denver”; > > session.Save(newUserSettings); > > > > This would result in two separate UserSettings rows in the db, both with > unique ids. It would also result in a completely new MailingAddress row, > but NOT a new Organization row. > > > > Serialization won’t work, because I can only say “serialize or ignore this > property”. I can’t say “when performing a deep copy, either cascade it to > this object or just copy over the reference, depending on the cascade > settings”. > > > > I was simply curious to see if anyone had encountered this issue before and > if they had any pointers. The need seems to pop up pretty often here. > > > > *From:* [email protected] [mailto:[email protected]] *On > Behalf Of *Fabio Maulo > *Sent:* Friday, June 19, 2009 10:28 AM > *To:* [email protected] > *Subject:* [nhusers] Re: deep copy aggregate root > > > > 2009/6/19 Yevhen.Bobrov <[email protected]> > > > I've tried creating fresh session and using SaveOrUpdateCopy to get > back clone. > But the problem I see now (maybe a bug until someone can prove that > this is by design) that SaveOrUpdateCopy do not create clones of > collections. > > > > The method is session.Merge and its behaviour depend on cascade in the > mapping. > > The Merge work with entities so what you will have is each entity merged > even if inside a collection. > > If you want a completely new instance with DB values you should use Refresh > (another time refresh work depending on cascade in the mapping). > > > > Btw what you should do is a deep copy... annoyed to do it by your self ? > well... what we should do ? > > If you want an easy implementation of DeepCloner it is very easy. Define > all your entities as Serializable, manage the serialization attributes where > needed, and use the BinaryFormatter. > > > > -- > Fabio Maulo > > > > > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
