Accepted answer

What is the life-cycle of the data-context? Is it the same data-context, or a new one each time? (it should probably be the latter).

If you re-use a data-context, it is obliged to always give you back the same object when ever it seems the same identity. So if it has previously given you the version with 9, it'll keep giving you back that reference even when the underlying data changes.

At the moment, this still does a round-trip; to avoid the round-trip, you need to use:

var obj = ctx.SomeTable.Single(x=>x.Id == id);

i.e. if it already has the object with Id == id in the local identity cache, it won't perform a databae query at all.

any other construct will do a round trip. There is a fix in 4.0 so that .Where(x=>x.Id == id).Single() will avoid the round-trip, which should have with query syntax, i.e.

var obj = (from x in ctx.SomeTable
           where x.Id == id
           select x).Single();


Are you updating using one DataContenxt while the one you later query from is still alive?

If yes this is the respones you should expect.

If you created a new DataContenxt after the update or the update and the read are being done on the same DataContext you shoud get the right response.

Related Articles