/// <summary> /// Creates a command to delete all records /// </summary> /// <returns></returns> protected IDbCommand CreateDeleteAllCommand() { IDbCommand command = DbProviderFactory.CreateCommand(Provider); IDeleteQuery s = QueryFactory.CreateDeleteQuery(Db, Provider); s.SetTable(Table); command.CommandText = s.GetText(); return(command); }
public int Delete <T>(string tableName, Expression <Func <T, bool> > filter) { // Remember sql mode var previousSqlMode = this.SqlMode; SqlMode = SqlModes.Text; var mappingHelper = new MappingHelper(this); if (tableName == null) { tableName = MapRepository.Instance.GetTableName(typeof(T)); } var dialect = QGen.QueryFactory.CreateDialect(this); TableCollection tables = new TableCollection(); tables.Add(new Table(typeof(T))); var where = new WhereBuilder <T>(Command, dialect, filter, tables, false, false); IQuery query = QueryFactory.CreateDeleteQuery(dialect, tables[0], where.ToString()); Command.CommandText = query.Generate(); int rowsAffected = 0; try { OpenConnection(); rowsAffected = Command.ExecuteNonQuery(); } finally { CloseConnection(); } // Return to previous sql mode SqlMode = previousSqlMode; return(rowsAffected); }