when I have UI control that binded to database, when I create object and set the SessionManager.HasError to true to prevent the object to be inserted then when the control perform DataBind() function the dataobject execute insert also with the select. how can I perform selection without inserting my object

asked Feb 20 '11 at 04:19

Hala%20Aly's gravatar image

Hala Aly

One Answer:

From docomentation of SessionManager.HasErrors property:

/// <summary>
/// Gets or sets value indicating whether an error has occurred 
/// on execution of the current request and transaction should be rollbacked.
/// </summary>

So it doesn't anything except ensuring the transaction for the current web request is rolled back @ its completion.

That's how it really works:

protected virtual Pair<Session, IDisposable> ProvideSession()
  var newSession = Domain.OpenSession(); // Open, but don't activate!
  var transactionScope = newSession.OpenTransaction();
  var toDispose = transactionScope.Join(newSession);
  return new Pair<Session, IDisposable>(newSession, new Disposable(disposing => {
    try {
      if (!HasErrors) // That's the only action it is responsible for
    finally {

Thus if you'll set it to true, you'll see the insertion in the SQL Profiler log, bug actually inserted entry won't appear in the DB - because of further rollback.

answered Feb 20 '11 at 05:18

Alex%20Yakunin's gravatar image

Alex Yakunin

Thanks Alex, but I want to select some data but not inserting created object in the same time.How can I do that??because I has this case and I don't know how to handle it.

(Feb 20 '11 at 06:09) Hala Aly Hala%20Aly's gravatar image

Basically, there are two cases:

  • You don't want to insert the object, but want some other changes to be persisted. In this case you should care about this by your own (i.e. check the condition and don't insert, if this is necessary).
  • You don't want any changes to be persisted. That's the case when you should use HasErrors property.
(Feb 20 '11 at 08:14) Alex Yakunin Alex%20Yakunin's gravatar image

Dear Alex, thanks for your concern, but how can I handle the first case if the DataObjects.Net insert automatically when perform any select?? The second solution when using HasErrors it alseo insert when selecting. My question is how to stop DataObjects.Net from inserting when perform select statement,Is there an option or property to set???

(Feb 20 '11 at 11:39) Hala Aly Hala%20Aly's gravatar image

Is there a solution to my problem???Please any body respond because I must take a decision to use or not DataObjects.Net

(Feb 23 '11 at 05:14) Hala Aly Hala%20Aly's gravatar image

Sorry, I missed the comment. So the question is: what code is responsible for creating the entity that is being inserted? Can you manage to prevent entity creation? If not, can you remove the newly created entity before running a query?

(Feb 23 '11 at 07:27) Alex Yakunin Alex%20Yakunin's gravatar image

Concerning automatic insertion: DO tries to persist all the changes before running the query to ensure result consistency. If you'd like to prevent such behavior on query, you must use:

  • Either Session.DisableSaveChanges(Entity entity) method - it blocks flushing of changes for a particular entity;
  • Or use Session.DisableSaveChanges() method - it blocks flusing of all the cached changes.

Note that both methods return IDisposable that re-enables flushes of changes.

(Feb 23 '11 at 07:31) Alex Yakunin Alex%20Yakunin's gravatar image

Hello Hala Aly,

Was the solution suggested by Alex helpful?

(Feb 25 '11 at 11:28) Dmitri Maximov Dmitri%20Maximov'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: Feb 20 '11 at 04:19

Seen: 3,879 times

Last updated: Feb 25 '11 at 11:28

powered by OSQA