EF 分布式事务的封装
程序员文章站
2022-07-13 22:37:03
...
封装
public class UnitOfWork
{
public static void Invoke(Action action)
{
TransactionScope transaction = null;
try
{
transaction = new TransactionScope();
action.Invoke();
transaction.Complete();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}
使用
UnitOfWork.Invoke(() =>
{
using (IUserCompanyService iUserCompanyService = new UserCompanyService(new JDDbContext()))
{
//增删改
}
});
下一篇: EF 增删改查的语句的写法整理