Explanation:
Let's say I have a graph of objects nested at several levels in depth, and each object has a bi-directional connection with each other.
A -> B -> C -> D -> E
Or, in other words, A has set B , and B has reference to A , and B has set C and C has a link back to B , etc.
Now let's say that I want to edit some data for an instance of C In Winforms, I would use something like this:
var instanceOfC; using (var session = SessionFactory.OpenSession()) {
In plain English, we extract a permanent instance from the database, separate it, send it to the user interface layer for editing, then attach it again and save it back to the database.
Problem:
This is great for Winform applications, because we use the same entity all along, with the only difference being that it goes from permanent to disabled to permanent again.
The problem is that I am now using a web service and browser, sending JSON data. The object is serialized to a string and de-serialized to a new object. This is no longer a separate entity, but rather a transitional one, which simply has the same identifier as the constant identifier (and updated fields). If I use this object for updating, it will destroy the connection with B and D because they do not exist in this new transition entity.
Question:
My question is how do I serialize individual objects over the Internet for a client, get them back and save them, preserving any relationships that I have not explicitly changed? I know about ISession.SaveOrUpdateCopy and ISession.Merge() (do they seem to do the same?), But it will destroy the relationship anyway if I don't explicitly set it. I could copy the fields from the transition object to the permanent object one by one, but this does not work very well when it comes to relationships, and I would have to manually compare the versions.