- I fetch the object from the database (POCO object with proxy)
- I modify its property without saving changes
- I fetch it later on again from the database (I use the same object context)
- What is the value of the property?
For example if I have object context with collection Users then what is the result of the following:
ObjectContext o = ....;
User u = o.Users.First(u=>u.Id == 1);
Console.WriteLine(u.LastName); // I get 'test' for example
u.LastName = 'SomethingElse';
u = o.Users.First(u=>u.Id == 1);
Console.WriteLine(u.LastName); // What is the result??
If the result of the last statement is not the string “SomethingElse” then is there a way to achieve this funcionality?
That is the core feature of ORM tools called identity map pattern. Entity with unique key can be materialized only once per context so the second query will be default use the same instance without changing its values.
You can force the query to refresh values by either:
or by reloading the entity itself: