protected override AncestorResult UpdateAll <T>(IModel valueObject, Expression <Func <T, bool> > predicate) { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <MySqlParameter>(); var effectRows = 0; var tableName = valueObject.GetType().Name; var SqlString = new StringBuilder(); SqlString.Append("UPDATE " + tableName + " set "); // 2015-09-03 update set 欄位語法, 重構為 UpdateTranslate method. SqlString.Append(UpdateTranslate(valueObject, parameters, UpdateMode.All)); using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var expParameters = helper.Parameters; sqlString += SqlString.ToString(); sqlString += whereString; //var paras = from p in expParameters // select new MySqlParameter(p.Name, (MySqlDbType)GetDbType(p.Type), // p.Value, ParameterDirection.Input); var paras = expParameters.Select(x => { var parameter = new MySqlParameter(x.Name, (MySqlDbType)GetDbType(x.Type)); parameter.Value = x.Value; parameter.Direction = ParameterDirection.Input; return(parameter); }); parameters.AddRange(paras); isSuccess = DB.ExecuteNonQuery(sqlString, parameters, ref effectRows); returnResult.Message = DB.ErrorMessage; returnResult.EffectRows = effectRows; } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }
public AncestorResult Update <T>(IModel valueObject, Expression <Func <T, bool> > predicate) where T : class, new() { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <OracleParameter>(); var effectRows = 0; var tableName = valueObject.GetType().Name; SqlString = new StringBuilder(); SqlString.Append("UPDATE " + tableName + " set "); // 2015-09-03 update set 欄位語法, 重構為 UpdateTranslate method. UpdateTranslate(valueObject, parameters); using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var expParameters = helper.Parameters; sqlString += SqlString.ToString(); sqlString += whereString; var paras = from p in expParameters select new OracleParameter(p.Name, (OracleDbType)GetDbType(p.Type), p.Value, ParameterDirection.Input); parameters.AddRange(paras); isSuccess = DB.ExecuteNonQuery(sqlString, parameters, ref effectRows); returnResult.Message = DB.ErrorMessage; returnResult.EffectRows = effectRows; } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }
protected override AncestorResult QueryNoRowid <T>(Expression <Func <T, bool> > predicate) { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <MySqlParameter>(); var dataTable = new DataTable(); var SqlString = new StringBuilder(); using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var Parameters = helper.Parameters; var tableName = new T().GetType().Name; SqlString.Append("SELECT * FROM " + tableName); SqlString.Append(whereString); var paras = Parameters.Select(x => { var parameter = new MySqlParameter(x.Name, (MySqlDbType)GetDbType(x.Value.GetType().Name)); parameter.Value = x.Value; parameter.Direction = ParameterDirection.Input; return(parameter); }); parameters.AddRange(paras); isSuccess = DB.Query(SqlString.ToString(), parameters, ref dataTable); returnResult.Message = DB.ErrorMessage; returnResult.DataList = dataTable.ToList <T>(); } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }
protected override AncestorResult Delete <T>(Expression <Func <T, bool> > predicate) { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <MySqlParameter>(); var dataTable = new DataTable(); var effectRows = 0; using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var Parameters = helper.Parameters; var tableName = new T().GetType().Name; sqlString = "DELETE FROM " + tableName; // 2015-09-03 sqlString += whereString; var paras = Parameters.Select(x => { var parameter = new MySqlParameter(x.Name, (MySqlDbType)GetDbType(x.Type)); parameter.Value = x.Value; parameter.Direction = ParameterDirection.Input; return(parameter); }); parameters.AddRange(paras); isSuccess = DB.ExecuteNonQuery(sqlString, parameters, ref effectRows); returnResult.Message = DB.ErrorMessage; returnResult.EffectRows = effectRows; } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }
public AncestorResult QueryNoRowid <T>(Expression <Func <T, bool> > predicate) where T : class, new() { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <OracleParameter>(); var dataTable = new DataTable(); SqlString = new StringBuilder(); using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var Parameters = helper.Parameters; var tableName = new T().GetType().Name; SqlString.Append("SELECT * FROM " + tableName); SqlString.Append(whereString); var paras = from parameter in Parameters select new OracleParameter(parameter.Name, (OracleDbType)GetDbType(parameter.Type), parameter.Value, ParameterDirection.Input); parameters.AddRange(paras); isSuccess = DB.Query(SqlString.ToString(), parameters, ref dataTable); returnResult.Message = DB.ErrorMessage; returnResult.DataList = dataTable.ToList <T>(); } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }
public AncestorResult Delete <T>(Expression <Func <T, bool> > predicate) where T : class, new() { string whereString = string.Empty; var isSuccess = false; var sqlString = string.Empty; var returnResult = new AncestorResult(); var parameters = new List <OracleParameter>(); var dataTable = new DataTable(); var effectRows = 0; using (LambdaExpressionHelper helper = new LambdaExpressionHelper(DbSymbolize, DbLikeSymbolize)) { try { var rootExp = predicate.Body as Expression; whereString = helper.Translate(rootExp); var Parameters = helper.Parameters; var tableName = new T().GetType().Name; sqlString = "DELETE FROM " + tableName; // 2015-09-03 sqlString += whereString; var paras = from parameter in Parameters select new OracleParameter(parameter.Name, (OracleDbType)GetDbType(parameter.Type), parameter.Value, ParameterDirection.Input); parameters.AddRange(paras); isSuccess = DB.ExecuteNonQuery(sqlString, parameters, ref effectRows); returnResult.Message = DB.ErrorMessage; returnResult.EffectRows = effectRows; } catch (Exception exception) { returnResult.Message = exception.ToString(); isSuccess = false; } } returnResult.IsSuccess = isSuccess; return(returnResult); }