/// <summary>
        /// 软删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        internal async virtual Task <int> SoftDelete <T>(T entity, string softDeleteField, int value = 0, string PrimaryKey = "", bool IngnorIntDefault = true)
            where T : AttrEntityBase
        {
            int result = 0;

            await this.TryCatch(async() =>
            {
                string sql = entity.SoftDeleteByCondition(softDeleteField, value, PrimaryKey, IngnorIntDefault);
                result     = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 直接更新实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="IgnorIntDefault"></param>
        /// <returns></returns>
        internal async virtual Task <int> UpdateField <T>(T entity, string PrimaryKey = "", bool IgnorIntDefault = true)
            where T : AttrEntityBase
        {
            int result = 0;

            await this.TryCatch(async() =>
            {
                string sql = entity.UpdateField(PrimaryKey);
                result     = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 根据指定的字段删除
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        internal async virtual Task <int> Delete <T>(T entity, string[] condition)
            where T : AttrEntityBase
        {
            int result = 0;

            await this.TryCatch(async() =>
            {
                string sql = entity.DeleteByCondition(condition);
                result     = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 新增返回受影响行数
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        internal async virtual Task <int> Insert <T>(T entity)
            where T : AttrEntityBase
        {
            int result = 0;

            await this.TryCatch(async() =>
            {
                string sql = entity.InsertEntity();
                result     = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 批量新增(非参数化,建议在大批量插入数据时使用)
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entities"></param>
        /// <returns></returns>
        internal async Task <int> NonPatameterBatchInsert <TEntity>(TEntity[] entities) where TEntity : AttrEntityBase, new()
        {
            int result = 0;

            if (entities?.Count() > 0)
            {
                string sql = entities.BatchInsertEntity();
                await this.TryCatch(async() =>
                {
                    result += await DbExtend.ExecuteNonQuery <AttrEntityBase>(Context, sql.ToString(), null, Tran);
                    return(sql.ToString());
                });
            }
            return(result);
        }
        /// <summary>
        /// 根据Dto模型字段特性更新指定表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dto"></param>
        /// <param name="IgnorIntDefault"></param>
        /// <returns></returns>
        public async virtual Task <int> UpdateDtoAttributeField <T>(T dto, bool IgnorIntDefault = true)
            where T : AttrBaseModel
        {
            string sql    = dto.UpdateFieldByDtoAttribute <T>(IgnorIntDefault);
            int    result = 0;

            if (string.IsNullOrEmpty(sql))
            {
                throw new AttrSqlException("请完善需要编辑的信息!");
            }
            await this.TryCatch(async() =>
            {
                result = await DbExtend.ExecuteNonQuery(Context, sql, dto, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 更新有值的字段,更新条件为字段中第一个包含ID的字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="Primary">主键字段,不指定则默认实体第一个带有Id的字段为主键</param>
        /// <param name="IgnorIntDefault"></param>
        /// <returns></returns>
        internal async virtual Task <int> UpdateHasValueField <T>(T entity, string Primary = "", bool IgnorIntDefault = true)
            where T : AttrEntityBase
        {
            string sql    = entity.GetUpdateField(Primary, IgnorIntDefault);
            int    result = 0;

            if (string.IsNullOrEmpty(sql))
            {
                throw new AttrSqlException("请完善需要编辑的信息!");
            }
            await this.TryCatch(async() =>
            {
                result = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 根据Dto特性配置为更新条件,更新有值的字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <param name="IgnorIntDefault"></param>
        /// <returns></returns>
        internal async virtual Task <int> UpdateHasValueFieldByDto <TDo, TEntity>(TDo dto, TEntity entity, bool IgnorIntDefault = true)
            where TDo : AttrBaseModel
            where TEntity : AttrEntityBase
        {
            string sql    = dto.UpdateFieldByEntityCondition(entity, IgnorIntDefault);
            int    result = 0;

            if (string.IsNullOrEmpty(sql))
            {
                throw new AttrSqlException("请完善需要编辑的信息!");
            }
            await this.TryCatch(async() =>
            {
                result = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                return(sql);
            });

            return(result);
        }
        /// <summary>
        /// 批量新增(参数化)
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        internal async Task <int> BatchInsert <TEntity>(TEntity[] entities) where TEntity : AttrEntityBase, new()
        {
            int result = 0;

            if (entities?.Count() > 0)
            {
                await this.TryCatch(async() =>
                {
                    //默认事务新增
                    if (Tran == null)
                    {
                        await TransactionRun(async() =>
                        {
                            foreach (var item in entities)
                            {
                                string sql = item.InsertEntity();
                                result    += await DbExtend.ExecuteNonQuery(Context, sql.ToString(), item, Tran);
                            }
                            if (result == entities.Length)
                            {
                                return(AttrResultModel.Success());
                            }
                            else
                            {
                                return(AttrResultModel.Error("批量新增失败!"));
                            }
                        });
                    }
                    else
                    {
                        foreach (var item in entities)
                        {
                            string sql = item.InsertEntity();
                            result    += await DbExtend.ExecuteNonQuery(Context, sql.ToString(), item, Tran);
                        }
                    }
                    return("");
                });
            }
            return(result);
        }
        /// <summary>
        /// 执行指定的更新语句
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        internal async virtual Task <int> ExecUpdateSql <T>(T entity, string sql)
            where T : AttrEntityBase
        {
            int result = 0;

            if (string.IsNullOrEmpty(sql))
            {
                throw new AttrSqlException("请完善需要编辑的信息!");
            }
            await this.TryCatch(async() =>
            {
                if (entity != null)
                {
                    result = await DbExtend.ExecuteNonQuery(Context, sql, entity, Tran);
                }
                else
                {
                    result = await DbExtend.ExecuteNonQuery(Context, sql, Tran);
                }
                return(sql);
            });

            return(result);
        }