public int Execute(Type elementType, IDictionary <MemberExpression, object> properties, Expression predicate) { MySqlUpdateCommandBuilder updateBuilder = new MySqlUpdateCommandBuilder(elementType.Name); foreach (var item in properties) { updateBuilder.AddColumn(item.Key.Member.Name, item.Value); } if (predicate != null) { MySqlWherePartsCommandBuilder whereBuider = new MySqlWherePartsCommandBuilder(updateBuilder.Parameters); Expression expression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(predicate); MySqlWhereClauseVisitor visitor = new MySqlWhereClauseVisitor(); visitor.Translate(expression, whereBuider); updateBuilder.WhereParts = whereBuider.WherePartsBuilder.ToString(); } this.sessionProvider.ExecutedCommandBuilder = updateBuilder; return(this.sessionProvider.ExecuteNonQuery(updateBuilder)); }
/// <summary> /// 解析 Where 语句 /// </summary> /// <param name="whereClause"></param> /// <param name="queryModel"></param> /// <param name="index"></param> public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index) { MySqlWherePartsCommandBuilder whereBuilder = new MySqlWherePartsCommandBuilder(this.commandBuilder.Parameters); MySqlWhereClauseVisitor visitor = new MySqlWhereClauseVisitor(); visitor.Translate(whereClause.Predicate, whereBuilder); commandBuilder.WhereParts.Add(whereBuilder.ToString()); base.VisitWhereClause(whereClause, queryModel, index); }
public int Execute(Type elementType, Expression predicate) { MySqlDeleteCommandBuilder deleteBuilder = new MySqlDeleteCommandBuilder(elementType.Name); if (predicate != null) { MySqlWherePartsCommandBuilder whereBuilder = new MySqlWherePartsCommandBuilder(deleteBuilder.Parameters); Expression expression = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees(predicate); MySqlWhereClauseVisitor visitor = new MySqlWhereClauseVisitor(); visitor.Translate(expression, whereBuilder); deleteBuilder.WhereParts = whereBuilder.WherePartsBuilder.ToString(); } this.sessionProvider.ExecutedCommandBuilder = deleteBuilder; return(this.sessionProvider.ExecuteNonQuery(deleteBuilder)); }
/// <summary> /// 翻译表达式 /// </summary> /// <returns></returns> public void Translate(Expression expression, MySqlWherePartsCommandBuilder commandBuilder) { this.commandBuilder = commandBuilder; this.VisitExpression(expression); }