Inside of a filter I’m trying to insert into another table. There is an existing transaction however the queries in the filter never save.
Somewhere in the app.
public void DoSomething() {
using (var trans = Db.OpenTransaction()) {
Db.Save(new Test() { Id=5});
}
}
```
Filter:
```csharp
OrmLiteConfig.InsertFilter = (dbCmd, row) => {
if (row.GetType().GetCustomAttribute<NoTrackAttribute>()!=null) return;
IDbConnection db = dbCmd.Connection;
if (dbCmd.Transaction!=null)
{
db = dbCmd.Transaction.Connection;
}
try
{
var modelDef = row.GetType().GetModelMetadata();
//var name = modelDef.ModelName;
var dialectProvider = dbCmd.GetDialectProvider();
var tableName = dialectProvider.NamingStrategy.GetTableName(modelDef);
var key = modelDef.GetPrimaryKey(row);
var auditLog = new AuditLog();
auditLog.EventDateUTC = DateTime.UtcNow;
auditLog.TableName = tableName;
auditLog.EventType = 1; // This is hard coded, not sure what it needs to be
auditLog.RecordId = key.ToString();
var identity = db.Insert<AuditLog>(auditLog, selectIdentity: true); // fails here
List<AuditLogDetails> details = new List<AuditLogDetails>();
foreach (var def in modelDef.FieldDefinitions)
{
if (def == null || def.IsComputed || def.IgnoreOnInsert) continue;
var record = new AuditLogDetails()
{
AuditLogId = (int)identity,
ColumnName = def.Alias?.ToString() ?? def.Name, //def.FieldName might be too
NewValue = def.GetValue(row)?.ToString() ?? "",
};
db.Insert<AuditLogDetails>(
record);
}
} catch (Exception ex)
{
Log.Logger.Debug(ex.Message);
}
};
```
It fails with this:
ExecuteScalar 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.