I've got kind of "dumbed-down" entities coming in on an http request that I'm looking to save as simply as possible. These entities have all of their own data, but none regarding the associated entities (users, etc...).
Using Session.Merge seems to be doing a good enough job getting the detached entity back into the session, and I'm not losing any of the associated collections. But anything associated via a "References" relationship disappears when I save the merged entity. I don't think this is cascading behavior (I have cascade=none defined by convention).
Is there any way I can modify the merge behavior (via configuration or otherwise) so that I can merge these incomplete entities without breaking associations? I'm hoping to get rid of a lot of the "roll your own" merge code that is currently there.
I'm using fluent nhibernate for mapping if that chang开发者_StackOverflowes available options.
edit:
I ended up exposing merge through a base repository but making the method virtual so I could deal with this type of situation in specific implementations as needed. Seems to work well enough.
NHibernate's "Merge" method does something a little different than what you think, I think. It basically attaches the object and its children to the session, replacing any copy of the same record that's already there. What you need is something that acts more like an SVN merge, taking your changes from the object graph you pass in, and integrating them into the existing object graph. This is beyond NH's capabilities.
Sorry to say, but I think you're gonna be stuck rolling your own on this one. Making NH do something like this would require configuring a lot of rules about things like "when is a null reference an actual change, and when should it be ignored", which can even change from case to case.
精彩评论