Otis wrote:
The only way to avoid refetches is to edit clones indeed, and when confirmed, make the clones the real entities and toss away the old ones.
Cloning isn't that hard, you can use the binary serializer to serialize to a MemoryStream, then seek the stream to the beginning, then deserialize the MemoryStream into a new object and you're done. This of course clones the complete graph, which can be big, but if you keep the data hierarchy thin, i.e.: only fetch the data REQUIRED for the edit page, it should be ok.
Keep in mind that this problem you're facing is because you try to work around the principle of a webpage: you try to make a stateless architecture become stateful, which requires facilities which aren't there: as you said, you don't know when the user closes the browser.
But what happens when the user opens 2 browser windows and edits in one and refreshes in the other? Are these in sync? Or is that undefined?
I was just thinking about the binary serialization too and had started to implement it when I came to check for anwers to my post.. :-) Infact I usually load stuff I need to edit during the edit itself so the entity graph should not be too big.
About turning stateless architecture in a stateful one that is true, but then to give the user the tools required in my project I have no other choice. They want a rich UI and it must be on the web, so I'm trying to 'port' a desktop version of a framework we have to asp.net, with the obvious problems due to like you said an architecture which doesn't have the facilities required.
About the user opening two windows and refreshing one I was actually going to give each page a unique id, and it will retrieve the data from the state manager using this id, so two browser windows would work on separate data. You might say waste of memory but it's unlikely that a user will actually open two windows at the same time, and if he/she does then she'll get two separate objects to edit, and then everything will be handled by conccurrency control: last one to save is asked to force changes because someone else saved before him/her.
Or, I can devise something to know if that entity is already being edited and deny the user the second window.
Thanks Frans