As I understand, you suggest something like this:
|ObjectContainer cont = Page.Session["MyContainer"] as ObjectContainer;
|IObjectScope scope = globalScope;
// there is no active scope's transaction now
|object theObject = cont.NamedList("MyName");
// below lines instead of cont.CopyTo and scope.Transaction.Commit
|ObjectContainer.ChangeSet chSet =
ObjectContainer.Verify.Changed, scope, true, true);
Is this true? If yes:
In the first scenario it works - but CommitChanges begins and commits the scope's transaction. It's not good because I want to do some additional database updates in the same transaction (e.g. CommitChanges changes some object's data that should trigger modification of access rights to this object). In this case it is impossible - I must do it in a separate transaction.
In my original scenario this part of the code is like this:
|additionalSave(scope, ...); //
In the second scenario - problem remains exactly the same: cont.Transaction.Commit changes data in the database and CommitChanges fails with OptimisticVerificationFails.
The main goal of the presented code is to implement the algorithm:
- an object is presented in a preview mode
- the user clicks Edit; this loads the object from the database again and stores it in a container (that is stored in a session variable); then the page is switched to the edit mode
- the user enters some changes and clicks Save; this retrieves the object from the container, applies the changes and saves it to the database - being able to check whether the object hasn't been modified meantime.
The second scenario is for implementing some functions that change the displayed object while in preview mode (e.g. a button "Change status to 'Approved'"). In this case I must check out this object, do changes and check it in - and the best way to do it is to use the existing methods of switching to the edit mode and saving the object to the database.