Batch update inside a transaction

Posts   
 
    
Posts: 6
Joined: 12-Jul-2006
# Posted on: 20-Jul-2007 12:00:41   

I'm trying to perform a batch update (without fetching the data first) inside a transaction, but when I view the executed SQL code (in the Profiler) I don't see the transaction at all.

I'm I overlooking something (or just don't understand transactions? wink )?


private static Guid GenerateBatchId()
        {
            Transaction transaction = new Transaction(IsolationLevel.Serializable, "Batch creation transaction");

            try
            {
                Guid guid = Guid.NewGuid();

                MeasurementSessionEntity measurementSessionEntity = new MeasurementSessionEntity();
                measurementSessionEntity.BatchId = guid;
                
                IPredicateExpression updateFilter = new PredicateExpression(MeasurementSessionFields.BatchId == DBNull.Value);
                
                MeasurementSessionCollection measurementSessionCollection = new MeasurementSessionCollection();

                transaction.Add(measurementSessionCollection);

                measurementSessionCollection.UpdateMulti(measurementSessionEntity, updateFilter);

                transaction.Commit();

                return guid;
            }
            catch (Exception)
            {
                // abort, roll back the transaction
                transaction.Rollback();
                throw;
            }
            finally
            {
                // clean up. Necessary action.
                transaction.Dispose();
            }
        }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Jul-2007 15:38:57   

The collwction added to the transaction doesn't have any operation performed on it. UpdateMulti() works directly on the database.

Instead, look for an overload of the UpdateMulti() which accepts a transaction parameter.

Posts: 6
Joined: 12-Jul-2006
# Posted on: 20-Jul-2007 16:11:10   

Walaa wrote:

Instead, look for an overload of the UpdateMulti() which accepts a transaction parameter.

And what if there isn't any?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Jul-2007 16:39:35   

I think I was mistaken. I was speaking about DaoBase.UpdateMulti() which does accept a transaction.

Which runtime library version are you using?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 20-Jul-2007 21:42:05   

UpdateMulti uses the transaction set of the collection it is called on, so that's covered.

Let's look at the code:

Pieter wrote:

I'm trying to perform a batch update (without fetching the data first) inside a transaction, but when I view the executed SQL code (in the Profiler) I don't see the transaction at all.

I'm I overlooking something (or just don't understand transactions? wink )?


private static Guid GenerateBatchId()
        {
            Transaction transaction = new Transaction(IsolationLevel.Serializable, "Batch creation transaction");

THis line above already starts the transaction. It creates an open connection and opens a transaction. So after this line above it should have opened a connection AND a transaction.

So the problem is only that you don't see the transaction in the profile or is it that there's no action performed on the DB?

Frans Bouma | Lead developer LLBLGen Pro