how i can use transactions in dapper C#. my problem is i need to lock a table so i use a BeginTransaction, i do others transactions and until i finish these transactions i can do of commit, with the code that i show you. it can do it but when i receive 2 transactions at the same time, one transaction does not close good the conection. Thanks.
I want to do this but with dapper.
public int UpdateStan(PosDTO posParams)
{
int result = cnn.Execute(new Templates.Queries.upDateStan().TransformText(), new
{
id_merchant = posParams.idMerchant
}, transaction);
transaction.Commit();
cnn.Close();
cnn.Dispose();
return result;
}
public BatchStanDTO getBatchStan(PosDTO posDto)
{
cnn = _sodexoSource.Create();
cnn.Open();
transaction = cnn.BeginTransaction();
return cnn.Query<BatchStanDTO>(new Templates.Queries.getBatchStan().TransformText(), new { idMerchant = posDto.idMerchant }, transaction).FirstOrDefault();
}
public void rollbackTran()
{
try
{
transaction.Rollback();
}
catch (Exception ex)
{
}
}