So hopefully with some CSLA skills out there can help me see a better way with this one. I have a situation where I want to manually create my transaction from outside the object and set my transactionAttribute to manual.
So I have some code that looks like this:
using (SqlConnection conn ConnectionManager<SqlConnection>.GetManager("Db").Connection)
{
connectionTransaction = conn.BeginTransaction();
objectRef = objectRef.Save();
//other logic here
objectRef = objectRef.Save();
connectionTransaction.Commit();
}
Then inside the save method there is something like this for the data access:
using (var conn = ConnectionManager<SqlConnection>.GetManager("Db").Connection)
{
using (var cm = conn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "Proc_Name";
// param definitions
cm.ExecuteNonQuery();
}
}
When I do this I receive the following error:
ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
Ok so that makes sense what it is saying and I could easily fix by assigning the transaction to the command. But I'm wondering if this is actually structured correctly according to CSLA best practices. I can't seem to find a good example in the book I recently got.
I just can't imagine that it is good practice to tell my domain object code to behave like it is in a transaction when there could be times when it isn't.
Can anyone show me the light on what I need to do to fix this correctly?