C# LINQ 使用事务删除主从表数据
C# 全选
/// <summary>
/// 删除主从表数据
/// </summary>
/// <param name="docNo">单据号码</param>
/// <returns></returns>
public bool Delete(string docNo)
{
try
{
_Database.BeginTransaction();
var master = _Database.GetQueryable<tb_Borrow_Paper>().Where(w => w.BRNO == docNo).FirstOrDefault();
var details = _Database.GetQueryable<tb_Borrow_Papers>().Where(w => w.BRNO == docNo).ToList();
int count1 = _Database.Remove<tb_Borrow_Paper>(master);
int count2 = _Database.Remove<tb_Borrow_Papers>(details);
_Database.CommitTransaction();
//保存数据日志
if (count1 > 0 || count2 > 0)
_Log.Log(DataLogType.delete, "Borrow_Paper - 删除成功", nameof(tb_Borrow_Paper), docNo, _Loginer.Account, master, details);
return count1 + count2 > 0;
}
catch (Exception e)
{
_Database.RollbackTransaction();
throw;
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFramework.EF C/S框架网