I'm really stuck on a problem of refetch entity's fields value from data base in single transaction.


using (var session = domain.OpenSession()) {
  using (var transactionScope = session.OpenTransaction()) {
    var person = session.Query.Single<Person>(10);

    // at this point Name == "Obama"
    var name = person.Name;

    // changing person's name

    // and now we want to requery this entity with updated fields
    person = session.Query.Single<Person>(10);

    // but name is still == "Obama";
    // it returned from cache
    // how to force session to renew cache of this entity?
    name = person.Name;


public void ChangePerson(int id)
    // in some reason changes is made in different session and transaction
    using (var session = domain.OpenSession()) {
      using (var transactionScope = session.OpenTransaction()) {
        var person = session.Query.Single<Person>(Id);
        person.Name = "James";

my DO Version is 4.5

asked Oct 16 '12 at 01:47

Dmitry%20F's gravatar image

Dmitry F

edited Oct 16 '12 at 01:56

One Answer:

Hello Taiwan,

any LINQ query by-passes session cache. The following code should work:

person = session.Query.All<Person>().Single(p => p.Id == 10);

Please note, that DataObjects.Net uses repetable read isolation level by default. Your changes will not be visible because you've already read this row in this transaction. To make it working use read committed isolation level: either by passing it explicitly to OpenTransaction method or by setting DefaultIsolationLevel in your SessionConfiguration.

answered Oct 16 '12 at 03:47

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov

Ok, i'll try this. I'm use snapshot isolation mode.

(Oct 16 '12 at 07:21) Dmitry F Dmitry%20F's gravatar image

Thank you. Your solution just works. Why this behaviour of DO is not documented?

(Oct 16 '12 at 07:27) Dmitry F Dmitry%20F's gravatar image

Thanks for noting, we're currently reworking our manual. It will include information about default isolation level and LINQ queries/session cache interoperation.

(Oct 17 '12 at 04:12) Denis Krjuchkov Denis%20Krjuchkov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview


Once you sign in you will be able to subscribe for any updates here



Asked: Oct 16 '12 at 01:47

Seen: 1,615 times

Last updated: Oct 17 '12 at 04:12

powered by OSQA