C#中事务的用法。
作者:互联网
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
using (IDbTransaction tran = conn.BeginTransaction())
{
try
{
flag = await conn.ExecuteAsync(Applysql, Item, tran) > 0;
if (Item.Status==1)
{
flag = await conn.ExecuteAsync(Usersql, Item, tran) > 0;
var list = await userRepository.Get(new User() { Id = Item.Creater });
String hingeString = JsonConvert.SerializeObject(list);
flag = GetuiHelper.Send(Item.Creater, hingeString);
}
flag = await conn.ExecuteAsync(Enterprisesql, Item, tran) > 0;
tran.Commit();提交事务
conn.Close();
}
catch (Exception ex)
{
flag = false;
tran.Rollback();回滚事务
conn.Close();
}
}
}
标签:事务,await,ExecuteAsync,C#,tran,用法,Item,flag,conn 来源: https://blog.csdn.net/VisageNocturne/article/details/112094789