Otis wrote:
You dont need to do all that hassle. Take a look at the Transaction class, which is generated. That class is always used when creating a transaction. In the constructor it creates a connection. So if you alter that template to emit some additional code which then, when it creates the connection and physical transaction, sends the contextinfo statement, it should always work when a transaction is created (directly by you in code or indirectly by llblgen pro when you save entities recursively)
Mmmm I see. Might need some more hand holding:
1) I still need to override OnSave and OnSaveCompleted to create & commit the transaction right?
2) As for modifying Transaction.cs - Which method should I put the code for "SET CONTEXT_INFO <value>" - I am assuming CreatePhysicalTransaction .
I will start implementing this now and just see what happens, LOL.
Edit: This is what I have, <deleted>:
protected override System.Data.IDbTransaction CreatePhysicalTransaction()
{
IDbTransaction Trans = DbUtils.CreateTransaction(base.ConnectionToUse, base.TransactionIsolationLevel, this.Name);
System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand();
Cmd.Connection = (System.Data.SqlClient.SqlConnection)base.ConnectionToUse;
Cmd.CommandText = "SET CONTEXT_INFO " + gContextInfo;
Cmd.Transaction = (System.Data.SqlClient.SqlTransaction)Trans;
Cmd.ExecuteNonQuery();
return Trans;
}
private Transaction Trans;
protected override void OnSave()
{
Trans = new Transaction(IsolationLevel.Unspecified, "Trans");
Trans.Add(this);
}
protected override void OnSaveComplete()
{
Trans.Commit();
base.OnSaveComplete();
}
Edit: It does WORK! It works perfect!!!
YOU ROCK DUDE!