using Yw.DAL.SQLite; namespace HStation.DAL.SQLite { /// /// /// public partial class ValveGroup : BaseDAL_Sorter, IValveGroup { /// /// /// public override ConnectionConfig ConnectionConfig { get { return Assets.ConfigHelper.SQLiteConnectionConfig; } } //删除拓展 public bool DeleteEx(long ID) { if (ID < 0) { return default; } using (var db = new SqlSugarClient(ConnectionConfig)) { try { db.BeginTran(); var group = db.Queryable().ToList().Find(x => x.ID == ID); var groupresult = db.Deleteable(group).ExecuteCommand() > 0; if (!groupresult) { db.RollbackTran(); return default; } else { var idlist = db.Queryable() .Where(x => x.ValveGroupID == group.ID) .Select(x => x.AssetsValveMainID) // 假设 ValveGroupID 是与 AssetsValveMain 关联的外键 .ToList(); var main = db.Queryable() .Where(x => x.ValveGroupID == group.ID) .ToList(); if (main.Count > 0) { var Modelresult = db.Deleteable(main).ExecuteCommand() > 0; if (!Modelresult) { db.RollbackTran(); return default; } else { var Map = db.Queryable().ToList(); var Mapresult = db.Deleteable() .In(x => x.ID, idlist) .ExecuteCommand() > 0; if (!Mapresult) { db.RollbackTran(); return default; } } } } db.CommitTran(); return groupresult; } catch (Exception ex) { db.RollbackTran(); throw; } } } } }