/// <summary> /// 删除数据 /// </summary> /// <typeparam name="T">必须是可实例化的(IEntity)类型</typeparam> /// <param name="whereClip">删除的条件信息(必须有)</param> /// <param name="bDataBase">数据库名称(默认为当前数据库)</param> /// <param name="result">是否需要返回结果才继续执行,默认为true</param> /// <param name="tableFunc">替换表名称</param> public void DeleteTS <T>(WhereClip <T> whereClip, bool result, string bDataBase = ConstExpression.DataBase, Expression <Func <Type, string> > tableFunc = null) where T : class, IEntity { var dms = new DMS <T>(bDataBase, ConstExpression.WithLock, ConstExpression.NeedParams, ConstExpression.NeedQueryProvider).DMSDelete(whereClip); if (tableFunc != null) { dms.ReplaceTable(tableFunc); } string resultSql = dms.GetResultSql(); if (resultSql.ToLower().IndexOf("where") == -1) { Log.Debug(ReflectionUtils.GetMethodBaseInfo(System.Reflection.MethodBase.GetCurrentMethod()), resultSql + "没有where条件,这是非常危险的操作", null); throw new DMSFrameException(resultSql + "没有where条件"); } TransactionScopeEntity tEntity = new TransactionScopeEntity() { DataParameter = dms.dynamicParameters, ResultSql = resultSql, ElementType = typeof(T), ResultFlag = result, ExcuteType = DMSExcuteType.DELETE, EntityName = typeof(T).FullName, }; changeInternalDbProvider(typeof(T)); TransactionScopeEntityList.Enqueue(tEntity); }
/// <summary> /// 编辑数据 /// </summary> /// <typeparam name="T">必须是可实例化的(IEntity)类型</typeparam> /// <param name="entity">编辑的实体参数,必须有字段进行编辑过</param> /// <param name="bDataBase">数据库名称(默认为当前数据库)</param> /// <param name="whereFunc">编辑的条件信息</param> /// <param name="result">是否需要返回结果才继续执行,默认为true</param> /// <param name="tableFunc">替换表名称</param> public void EditTS <T>(T entity, Expression <Func <T, bool> > whereFunc, bool result, string bDataBase = ConstExpression.DataBase, Expression <Func <Type, string> > tableFunc = null) where T : class, IEntity { T value = Activator.CreateInstance(typeof(T)) as T; var dms = new DMS <T>(bDataBase, ConstExpression.WithLock, ConstExpression.NeedParams, ConstExpression.NeedQueryProvider).DMSEdit <T>(entity, whereFunc); if (tableFunc != null) { dms.ReplaceTable(tableFunc); } string resultSql = dms.GetResultSql(); TransactionScopeEntity tEntity = new TransactionScopeEntity() { DataParameter = dms.dynamicParameters, ResultSql = resultSql, ElementType = entity.GetType(), ResultFlag = result, ExcuteType = DMSExcuteType.UPDATE, }; changeInternalDbProvider(typeof(T)); TransactionScopeEntityList.Enqueue(tEntity); }