I am using dapper with repository pattern. Below is the code for single repository insert. I need to call 2 or more repositories in service layer with transaction (in savecustomer method). How to apply transaction for the following method?
Protected void Execute(Action<IDbConnection> query) {
using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["myDB"].ConnectionString))
{
query.Invoke(db);
}
}
And my simplified call site:
public void SaveCustomer(CustomerDTO custDTO)
{
Execute(db => db.Execute(saveCustSp, custDTO, CommandType.StoredProcedure));
}