How can I read data from table with (nolock)? I don't want to initial a transaction. I want to have 2 separate context. 1 context for read with nolock and no change tracking (usually to read data and display to gridview, etc) - most of application had more than 50% read only.

1 context for read and had update request with change tracking and lock.


This thread was imported from our support forum. The original discussion may contain more detailed answer. Original topic by leovietnam.

asked Mar 22 '10 at 09:39

Editor's gravatar image


One Answer:

You can't do this with DO - we don't provide this option. It is:

  • Specific to SQL Server

  • Dangerous

  • Practically useless, if snapshot isolation is turned on.

If you're dealing with SQL Server > 2005, it's much better to use snapshot isolation. Reads are lock-free in this case. Other databases DO4 supports (Oracle, PostgreSQL) rely on MVVM (snapshot isolation is vary similar to MVVM), so it is unnecessary here.

And about change tracking: DO4 always track the changes, but tracking mode is different to one in EF. In case with WPF application you must use DisconnectedState to get similar tracking mode (actually, quite different inside, but effect is similar: nothing is automatically refreshed when DisconnectedState is attched; changes are persisted to underlying storage only after explicit ApplyChanges call + object versions are validated during this operation).

So in short, you anyway need DisconnectedState (see this chapter in Manual). And to avoid any possible locking on reads, I recommend to turn on snapshot isolation (this is much simpler then dealing with possible inconsistency - even in read-only mode).

answered Mar 22 '10 at 14:20

Alex%20Yakunin's gravatar image

Alex Yakunin

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: Mar 22 '10 at 09:39

Seen: 4,652 times

Last updated: Mar 22 '10 at 09:39

powered by OSQA