/// <summary> /// Remove all the instances of <typeparamref name="T"/> that satisfy the <paramref name="expression"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="expression"></param> public static void RemoveWhere <T>(Expression <Func <T, bool> > expression = null) { Type myObjectType = typeof(T); StringBuilder command = new StringBuilder(); var connectionName = Model.ConnectionName(myObjectType); using (var cmd = Execute.Command(connectionName)) { cmd.CommandType = System.Data.CommandType.Text; command.Append("DELETE FROM "); command.Append(Model.TableNameFullyQualified(typeof(T))); if (expression != null) { command.Append(" WHERE \n"); var parameters = new Dictionary <String, object>(); var visitor = new SqlExpressionVisitor <T>(command, parameters); var body = expression.Body; visitor.Visit(body); Execute.Utility.AddParametersToCommand(parameters, cmd, connectionName); } cmd.CommandText = command.ToString(); cmd.ExecuteNonQuery(); } }
public virtual String GenerateUpdate() { Command = new StringBuilder(); Command.Append("UPDATE\n"); Command.AppendFormat("\t[{0}]", this.TableAlias); Command.Append("\nSET\n"); Command.Append(String.Format("\t{0}", String.Join(",", _updateSets))); Command.Append("\nFROM"); Command.AppendFormat("\n\t{0} [{1}]", this.FullyQualifiedTableName, this.TableAlias); if (_whereClause != null) { Command.Append("\nWHERE\n"); var visitor = new SqlExpressionVisitor <T>(Command, Parameters, Members); visitor.Visit(_whereClause); } return(Command.ToString()); }