Hi,

We need to connect transactions from DO to a transaction that is opened for LINQ to SQL. We call a routine in the legacy code that adds rows to the DB. This action should be rolled back when the update of DO fails for some reason. Both transactions and updates are done in same instance of a MSSQL Database.

Here's the routine we are calling:

    /// <summary>
    /// Create a new Message in CIT and return a list of ids
    /// </summary>
    public static void CreateMeldingenVoorCitObjecten(long padOpdrachtId, List<CreateMeldingVoorCitObjectDataContract> citObjecten, Transaction transaction = null)
    {
        var nieuwCommand = new MeldingenMakenCommand(padOpdrachtId, citObjecten);
        nieuwCommand.Execute(transaction);
    }

We think we can use the EnlistTransaction(System.Transactions.Transaction transaction) method for linking the transactions together. If this is the way we should approach this we would need the Transaction object from the DO transaction. I don't see any property or method that can give me that.

Questions:

  • Is EnlistTransaction() the right way to get the functionality we want?
  • If so, can I get the Transaction object?

Regards Paul

asked May 08 '14 at 03:36

Paul%20Sinnema's gravatar image

Paul Sinnema
261858896

edited May 08 '14 at 03:44


One Answer:

Hello Paul,

DataObjects.Net does not use System.Transactions except the IsolationLevel enum.

However you can simply utilize it with DO as well as other code that uses SqlConnection.

using (var scope = new System.Transactions.TransactionScope()) {
  using (var session = domain.OpenSession())
  using (var tx = sesssion.OpenTransaction()) {
    tx.Complete();
  }
  // DataObjects.Net transaction is completed here
  scope.Complete();
}
// Actual database transaction is completed here

Alternatively you can obtain SqlConnection and SqlTransaction instances from DO session

var sql = session.Services.Get<DirectSqlAccessor>();
var connection = (SqlConnection) sql.Connection;
var transaction = (SqlTransaction) sql.Transaction;

and pass them to any code that needs to use the same transaction.

answered May 12 '14 at 04:36

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

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

powered by OSQA