public async Task DeleteOrgUnit(Guid ouid) { if (ouid == Guid.Empty) { throw new Exception("待删除的组织单元标识为空"); } var ou = await Entities.OrgUnit.LoadAsync(ouid); if (ou == null) { throw new Exception("找不到待删除的组织单元"); } if (ou.ParentId == null) { throw new Exception("不能删除根节点"); } //先删除组织单元 await SqlStore.Default.DeleteAsync(ou); //再尝试删除orgunit的基类实例 try { if (ou.BaseType == Entities.Emploee.TypeId) { var cmd = new SqlDeleteCommand <Entities.Emploee>(); cmd.Where(t => t.Id == ou.BaseId); await SqlStore.Default.ExecCommandAsync(cmd); } else if (ou.BaseType == Entities.Workgroup.TypeId) { var cmd = new SqlDeleteCommand <Entities.Workgroup>(); cmd.Where(t => t.Id == ou.BaseId); await SqlStore.Default.ExecCommandAsync(cmd); } else if (ou.BaseType == Entities.Enterprise.TypeId) { var cmd = new SqlDeleteCommand <Entities.Enterprise>(); cmd.Where(t => t.Id == ou.BaseId); await SqlStore.Default.ExecCommandAsync(cmd); } } catch (Exception) { /*do nothing*/ } }
public Task <int> ExecCommandAsync <TSource>(SqlDeleteCommand <TSource> cmd, DbTransaction txn = null) where TSource : SqlEntityBase { return(null); }