kulki wrote:
Thank you for a very well though out answer. Let me try to give you an example of a scenario which bothers me. This is in the context of a ASP.NET application. As soon as the user logs in I save the User object into a session Variable. Sometime later the user might decide to change his FirstName. Since there is no IdentityMap, its very possible that a new Instance of the user could be created. The FirstName is modified and then saved.
However now the copy of the User object stored in the session variable is now out of sync with the DataBase.
With an identity map you won't be helped either: what if your app runs in a webfarm scenario?
What you should do is to give an entity a uniquely identifying attribute, a PK, and one which is not easily changed, for example an artificial ID. Firstname + Lastname is not good enough. In your scenario, the new user is saved when its created. When he changes his name attribute, that's ok, save it again. If another entity with the same data is created, it's another entity, and you should check when you're creating THAT entity if it is a duplicate or not.
If somehow this copy could have been informed that its out of sync and made to refresh its data then it would have been great. If you have the time take a look at ActiveObjects (CSLA framework)
That's impossible to implement. Sure it works in a desktop app with a local database, but not in a webapp. First of all, there has to be a central system which controls every access to the db. In a webapp this is not possible, as asp.net performs appDomain recycling. Furthermore, a webfarm kills the concept also. And last but not least: webapps are more or less stateless, no matter how hard microsoft tries to tell you otherwise. It looks like they're not, but they are.
Well I think a framework must not automatically refresh the appropriate references, but should it not atleast raise events to inform that the object has been modified and therefore needs to be refreshed.
How can it know something has changed? perhaps you execute a query somewhere which alters an entity in the db. You won't get a signal back some record has been altered by a multi-row update statement. That's the point: if you consider your app stateless, you don't have these problems. However if you try to make it statefull, it will result in a lot of problems which all relate to the stateless nature of webapps.