大家好,又见面了,我是你们的朋友全栈君。
事务:
/// <summary> /// 删除考勤 /// </summary> /// <param name="dto">Id</param> /// <returns></returns> public ResultEntity<bool> DeleteAttend(DelAttendEditorDTO dto) { //SqlConnection con = new SqlConnection(@"Data Source=.SQLEXPRESS;database=aaaa;uid=sa;pwd=jcx"); //con.Open(); using (var context = new HRModelsContainer()) { var trans = context.Database.BeginTransaction(); try { foreach (var Id in dto.Ids) { //先删从表,再删主表 context.Database.ExecuteSqlCommand("DELETE FROM NoWorkDays WHERE ConfigId = @Id", new SqlParameter("@Id", Id)); context.Database.ExecuteSqlCommand("DELETE FROM AttendancesConfig WHERE Id = @Id", new SqlParameter("@Id", Id)); context.SaveChanges(); } trans.Commit(); } catch (Exception error) { trans.Rollback(); trans.Dispose(); throw error; } finally { trans.Dispose(); } } return GetResultEntity(true); }
转载于:https://www.cnblogs.com/likui-bookHouse/p/9618332.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/138630.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...