using Apache.NMS; using Apache.NMS.ActiveMQ; using Rhea.Common; using SqlSugar; using System; using System.Collections; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using Tiger.IBusiness; using Tiger.Model; namespace Tiger.Business { /// /// 数据库操作基础类 /// public class DbBase : Rhea.Common.DbBase, IDbBase//Rhea.Common.DbBase { /// /// 数据库操作基础类 /// /// public DbBase(DbClient db) : base(db) { } #region 添加操作 /// /// 把单个实体往数据库添加一行数据 /// /// /// 实体 /// 是否以异步方式执行 /// public new async Task> AddAsync(T entity, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Insertable(entity).ExecuteCommandAsync() : Db.Insertable(entity).ExecuteCommand(); action.Message = $"Insert {typeof(T).Name} entity into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Insert {typeof(T).Name} entity into database exception"); } return action; } /// /// 把实体List往数据库批量添加数据 /// /// /// 实体List /// 是否以异步方式执行 /// public new async Task> AddListAsync(List list, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Insertable(list).ExecuteCommandAsync() : Db.Insertable(list).ExecuteCommand(); action.Message = $"Insert {typeof(T).Name} entity list into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Insert {typeof(T).Name} entity list into database exception."); } return action; } #endregion 添加操作 #region 保存操作 /// /// 把单个实体往数据库保存一行数据,如果存在就更新,不存在就插入 /// /// /// 实体 /// 是否以异步方式执行 /// public new async Task> SaveAsync(T entity, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Saveable(entity).ExecuteCommandAsync() : Db.Saveable(entity).ExecuteCommand(); action.Message = $"Save {typeof(T).Name} entity into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Save {typeof(T).Name} entity into database exception"); } return action; } /// /// 把实体List往数据库批量保存数据,如果存在就更新,不存在就插入 /// /// /// 实体List /// 是否以异步方式执行 /// public new async Task> SaveListAsync(List list, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Saveable(list).ExecuteCommandAsync() : Db.Saveable(list).ExecuteCommand(); action.Message = $"Save {typeof(T).Name} entity list into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Save {typeof(T).Name} entity list into database exception."); } return action; } /// /// 把单个实体往数据库保存一行数据,如果存在就更新,不存在就插入 /// /// /// 实体 /// 是否以异步方式执行 /// public async Task> StorageableAsync(T entity, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Storageable(entity).ExecuteCommandAsync() : Db.Storageable(entity).ExecuteCommand(); action.Message = $"Storageable {typeof(T).Name} entity into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Storageable {typeof(T).Name} entity into database exception"); } return action; } /// /// 把实体List往数据库批量保存数据,如果存在就更新,不存在就插入 /// /// /// 实体List /// 是否以异步方式执行 /// public async Task> StorageableListAsync(List list, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Storageable(list).ExecuteCommandAsync() : Db.Storageable(list).ExecuteCommand(); action.Message = $"Storageable {typeof(T).Name} entity list into database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Storageable {typeof(T).Name} entity list into database exception."); } return action; } #endregion 保存操作 #region 修改操作 /// /// 从数据库中修改单个实体 /// /// /// 实体 /// 是否以异步方式执行 /// public new async Task UpdateAsync(T entity, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Updateable(entity).ExecuteCommandAsync() : Db.Updateable(entity).ExecuteCommand(); action.Message = $"Update {typeof(T).Name} entity from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Update {typeof(T).Name} entity from database exception"); } return action; } /// /// 根据实体List在数据库批量修改数据 /// /// /// 实体List /// 是否以异步方式执行 /// public new async Task UpdateAsync(List list, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Updateable(list).ExecuteCommandAsync() : Db.Updateable(list).ExecuteCommand(); action.Message = $"Update {typeof(T).Name} entity list from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Update {typeof(T).Name} entity list from database exception."); } return action; } /// /// 按UpdaterAble<T>对象从数据库中修改多个实体的某些字段 /// /// /// 实体List /// 是否以异步方式执行 /// public new async Task UpdateAsync(UpdateAble updater, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Updateable(updater.Items).UpdateColumns(updater.UpdateColumnList).ExecuteCommandAsync() : Db.Updateable(updater.Items).UpdateColumns(updater.UpdateColumnList).ExecuteCommand(); action.Message = $"Update some columns of {typeof(T).Name} entity list from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Update some columns of {typeof(T).Name} entity list from database exception"); } return action; } #endregion 修改操作 #region 删除操作 /// /// 从数据库中删除多个实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// 实体的主键ID数组 /// 是否以异步方式执行 /// public new async Task DeleteAsync(T newEntity, string[] primaryKeys, bool isAsync = true) where T : class, new() { var action = new ApiAction(false); try { var dbres = isAsync ? await Db.Deleteable().In(primaryKeys).ExecuteCommandAsync() : Db.Deleteable().In(primaryKeys).ExecuteCommand(); action.Message = $"Delete {typeof(T).Name} entity by primary keys from database success"; action.IsSuccessed = true; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity by primary keys from database exception"); } return action; } /// /// 从数据库中删除单个实体 /// /// /// 实体 /// 是否以异步方式执行 /// public new async Task DeleteAsync(T entity, bool isAsync = true) where T : class, new() { var action = new ApiAction(false); try { var dbres = isAsync ? await Db.Deleteable().Where(entity).ExecuteCommandAsync() : Db.Deleteable().Where(entity).ExecuteCommand(); action.Message = $"Delete {typeof(T).Name} entity from database success"; action.IsSuccessed = true; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity from database exception"); } return action; } /// /// 从数据库中删除实体List /// /// /// 实体List /// 是否以异步方式执行 /// public new async Task DeleteAsync(List list, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Deleteable().Where(list).ExecuteCommandAsync() : Db.Deleteable().Where(list).ExecuteCommand(); action.Message = $"Delete {typeof(T).Name} entity list from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity list from database exception"); } return action; } /// /// 根据Where语句删除满足条件的数据 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 是否以异步方式执行 /// public new async Task DeleteAsync(T newEntity, string where, bool isAsync = true) where T : class, new() { var action = new ApiAction(); try { var dbres = isAsync ? await Db.Deleteable().Where(where).ExecuteCommandAsync() : Db.Deleteable().Where(where).ExecuteCommand(); action.Message = $"Delete {typeof(T).Name} entity by where from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity by where from database exception"); } return action; } #endregion 删除操作 #region 查询操作 /// /// 从数据库中查询实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryAsync(T newEntity, bool isAsync = true, bool needInclude = false) { var action = new ApiAction>(); try { var queryable = Db.Queryable(); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToListAsync() : queryable.ToList(); action.Message = $"Query {typeof(T).Name} entity list from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity list from database exception"); } return action; } /// /// 根据Where语句从数据库中查询实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryAsync(T newEntity, string where, bool isAsync = true, bool needInclude = false) where T : class, new() { var action = new ApiAction>(); try { var queryable = Db.Queryable().Where(where); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToListAsync() : queryable.ToList(); action.Message = $"Query {typeof(T).Name} entity list by where from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity list by where from database exception"); } return action; } /// /// 按PageAble<T>对象返回实体当前Page的数据 /// /// /// 分页的参数实体 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryAsync(PageAble page, bool isAsync = true, bool needInclude = false) { var action = new ApiAction>(); try { var queryable = Db.Queryable(); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToPageAsync(page.pageIndex, page.pageSize) : queryable.ToPage(page.pageIndex, page.pageSize); action.Message = $"Query {typeof(T).Name} entity page from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity page from database exception"); } return action; } /// /// 分页直接返回PageAble<T> /// /// /// /// /// 是否需要导航查询 /// public async Task>> QueryPageAsync(PageAble page, bool isAsync = true, bool needInclude = false) { var action = new ApiAction>(); try { string where = page.sqlcmd; var queryable = Db.Queryable().Where(where); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToPageAsync(page.pageIndex, page.pageSize) : queryable.ToPage(page.pageIndex, page.pageSize); action.Data.draw = page.draw; action.Message = $"Query {typeof(T).Name} entity page from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity page from database exception"); } return action; } /// /// 按QueryAble<T>对象从数据库查询满足条件的数据 /// /// /// QueryAble的参数实体 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryAsync(QueryAble query, bool isAsync = true, bool needInclude = false) { var action = new ApiAction>(); try { var queryable = Db.Queryable().WhereIF(!query.where.IsNullOrEmpty(), query.where).OrderByIF(!query.order.IsNullOrEmpty(), query.order); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } if (query.page == null) { query.Items = isAsync ? await queryable.ToListAsync() : queryable.ToList(); } else { query.page = isAsync ? (await queryable.ToPageAsync(query.page.pageIndex, query.page.pageSize)) : queryable.ToPage(query.page.pageIndex, query.page.pageSize); query.Items = query.page.data; } action.Data = query; action.Message = $"Query {typeof(T).Name} entity by QueryAble from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity by QueryAble from database exception"); } return action; } /// /// 根据SQL语句从数据库中查询实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// SQL语句 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QuerySqlAsync(T newEntity, string sqlcmd, bool isAsync = true, bool needInclude = false) where T : class, new() { var action = new ApiAction>(); try { var queryable = Db.SqlQueryable(sqlcmd); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToListAsync() : queryable.ToList(); action.Message = $"Query {typeof(T).Name} entity list from database by sql command success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity list from database by sql command exception"); } return action; } /// /// 根据SQL语句从数据库中查询并按PageAble<T>对象返回当前Page的数据 /// /// /// 分页的参数实体 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QuerySqlAsync(PageAble page, bool isAsync = true, bool needInclude = false) where T : class, new() { var action = new ApiAction>(); try { var queryable = Db.SqlQueryable(page.sqlcmd); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToPageAsync(page.pageIndex, page.pageSize) : queryable.ToPage(page.pageIndex, page.pageSize); action.Data.draw = page.draw; action.Message = $"Query {typeof(T).Name} entity page from database by sql command success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity page from database by sql command exception"); } return action; } /// /// 从数据库中查询实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// 授权查询配置项 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryByAuthAsync(T newEntity, AuthOption options, bool isAsync = true, bool needInclude = false) where T : iTableHasAuth, new() { var action = new ApiAction>(); try { var queryable = Db.Queryable().ByAuth(options); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToListAsync() : queryable.ToList(); action.Message = $"Query {typeof(T).Name} entity list from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity list from database exception"); } return action; } /// /// 根据Where语句从数据库中查询实体 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 授权查询配置项 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryByAuthAsync(T newEntity, string where, AuthOption options, bool isAsync = true, bool needInclude = false) where T : iTableHasAuth, new() { var action = new ApiAction>(); try { var queryable = Db.Queryable().ByAuth(options).Where(where); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToListAsync() : queryable.ToList(); action.Message = $"Query {typeof(T).Name} entity list by where from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity list by where from database exception"); } return action; } /// /// 按PageAble<T>对象返回实体当前Page的数据 /// /// /// 分页的参数实体 /// 授权查询配置项 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryByAuthAsync(PageAble page, AuthOption options, bool isAsync = true, bool needInclude = false) where T : iTableHasAuth, new() { var action = new ApiAction>(); try { var queryable = Db.Queryable().ByAuth(options); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToPageAsync(page.pageIndex, page.pageSize) : queryable.ToPage(page.pageIndex, page.pageSize); action.Message = $"Query {typeof(T).Name} entity page from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity page from database exception"); } return action; } /// /// 分页直接返回PageAble<T> /// /// /// /// 授权查询配置项 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryByAuthPageAsync(PageAble page, AuthOption options, bool isAsync = true, bool needInclude = false) where T : iTableHasAuth, new() { var action = new ApiAction>(); try { string where = page.sqlcmd; var queryable = Db.Queryable().ByAuth(options).Where(where); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } action.Data = isAsync ? await queryable.ToPageAsync(page.pageIndex, page.pageSize) : queryable.ToPage(page.pageIndex, page.pageSize); action.Data.draw = page.draw; action.Message = $"Query {typeof(T).Name} entity page from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity page from database exception"); } return action; } /// /// 按QueryAble<T>对象从数据库查询满足条件的数据 /// /// /// QueryAble的参数实体 /// 授权查询配置项 /// 是否以异步方式执行 /// 是否需要导航查询 /// public async Task>> QueryByAuthAsync(QueryAble query, AuthOption options, bool isAsync = true, bool needInclude = false) where T : iTableHasAuth, new() { var action = new ApiAction>(); try { var queryable = Db.Queryable().ByAuth(options).WhereIF(!query.where.IsNullOrEmpty(), query.where).OrderByIF(!query.order.IsNullOrEmpty(), query.order); if (needInclude) { queryable = queryable.IncludesAllFirstLayer(); } if (query.page == null) { query.Items = isAsync ? await queryable.ToListAsync() : queryable.ToList(); } else { query.page = isAsync ? (await queryable.ToPageAsync(query.page.pageIndex, query.page.pageSize)) : queryable.ToPage(query.page.pageIndex, query.page.pageSize); query.Items = query.page.data; } action.Data = query; action.Message = $"Query {typeof(T).Name} entity by QueryAble from database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Query {typeof(T).Name} entity by QueryAble from database exception"); } return action; } #endregion 查询操作 #region 查询 Count /// /// 根据Where语句查询满足条件的实体的Count数量 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 是否以异步方式执行 /// public new async Task CountAsync(T newEntity, string where, bool isAsync = true) { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Queryable().Where(where).CountAsync() : Db.Queryable().Where(where).Count(); action.Message = $"Select Count[{typeof(T).Name} entity) success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Select Count[{typeof(T).Name} entity) exception"); } return action; } /// /// 根据Where语句查询满足条件的实体的Count数量 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 授权查询配置项 /// 是否以异步方式执行 /// public async Task CountByAuthAsync(T newEntity, string where, AuthOption options, bool isAsync = true) where T : iTableHasAuth, new() { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Queryable().ByAuth(options).Where(where).CountAsync() : Db.Queryable().ByAuth(options).Where(where).Count(); action.Message = $"Select Count[{typeof(T).Name} entity) success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Select Count[{typeof(T).Name} entity) exception"); } return action; } #endregion 查询 Count #region 查询 Exist /// /// 根据Where语句查询满足条件的Data实体是否存在 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 是否以异步方式执行 /// public new async Task IsExistAsync(T newEntity, string where, bool isAsync = true) { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Queryable().Where(where).AnyAsync() : Db.Queryable().Where(where).Any(); action.Message = $"Check {typeof(T).Name} entity is exist success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Check {typeof(T).Name} entity is exist exception"); } return action; } /// /// 根据Where语句查询满足条件的Data实体是否存在 /// /// /// 固定用法:通过ApiAction.NewDataEntity()创建ApiAction中指定类型对象 /// Where语句 /// 授权查询配置项 /// 是否以异步方式执行 /// public async Task IsExistByAuthAsync(T newEntity, string where, AuthOption options, bool isAsync = true) where T : iTableHasAuth, new() { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Queryable().ByAuth(options).Where(where).AnyAsync() : Db.Queryable().ByAuth(options).Where(where).Any(); action.Message = $"Check {typeof(T).Name} entity is exist success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Check {typeof(T).Name} entity is exist exception"); } return action; } #endregion 查询 Exist #region 执行SQL /// /// 执行SQL语句返回影响行数 /// /// 要执行的SQL语句 /// SQL语句的参数 /// 是否以异步方式执行 /// public new async Task ExecuteSqlCommandAsync(string sqlcmd, List parameters, bool isAsync = true) { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Ado.ExecuteCommandAsync(sqlcmd, parameters) : Db.Ado.ExecuteCommand(sqlcmd, parameters); action.Message = $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters.Select(q => new { ParameterName = q.ParameterName, Value = q.Value }))})"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters)})"); } return action; } /// /// 执行SQL语句返回影响行数 /// /// 要执行的SQL语句 /// SQL语句的参数 /// 是否以异步方式执行 /// public new async Task ExecuteSqlCommandAsync(string sqlcmd, bool isAsync = true, params SugarParameter[] parameters) { var action = new ApiAction(); try { action.Data = isAsync ? await Db.Ado.ExecuteCommandAsync(sqlcmd, parameters) : Db.Ado.ExecuteCommand(sqlcmd, parameters); action.Message = $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters.ToDictionary(it => it.ParameterName, it => it.Value))})"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters.ToDictionary(it => it.ParameterName, it => it.Value))})"); } return action; } /// /// 异步方式执行SQL语句返回影响行数 /// /// 要执行的SQL语句 /// SQL语句的参数 /// public new async Task ExecuteSqlCommandAsync(string sqlcmd, params SugarParameter[] parameters) { var action = new ApiAction(); try { action.Data = await Db.Ado.ExecuteCommandAsync(sqlcmd, parameters); action.Message = $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters.ToDictionary(it => it.ParameterName, it => it.Value))})"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Execute command success(SQL:{sqlcmd}, Params:{Db.Utilities.SerializeObject(parameters.ToDictionary(it => it.ParameterName, it => it.Value))})"); } return action; } #endregion 执行SQL #region 先删除后新增 /// /// 删除完更新 /// /// /// /// /// public new async Task AddAfterDeleteAsync(QueryAble query) where T : class, new() { var action = new ApiAction(); try { //保存到数据库 var db = Business.Biz.Db; var dbTran = db.UseTran(() => { var dbres = !query.where.IsNullOrEmpty() ? db.Deleteable().Where(query.where).ExecuteCommand() : db.Deleteable().ExecuteCommand(); if (query.Items.Count > 0) { db.Insertable(query.Items).ExecuteCommand(); } }); if (!dbTran.IsSuccess) { action.GetResponse().CatchExceptionWithLog(dbTran.ErrorException, $"作业保存到数据库异常"); } action.Message = $"Delete {typeof(T).Name} entity by where and add list in database success"; } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"Delete {typeof(T).Name} entity by where and add list in database exception"); } return action; } #endregion }//endClass }