EF 分布式事务的封装

封装

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()))
   {
        //增删改
   }
});
发布了143 篇原创文章 · 获赞 117 · 访问量 4218

猜你喜欢

转载自blog.csdn.net/weixin_41181778/article/details/103941343
EF