Table of Contents

Method DeleteRecords

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

DeleteRecords(Delete)

Deletes one or more records from a table based on specified criteria.

public int DeleteRecords(Delete delete)

Parameters

delete Delete

A Delete object defining which records to delete.

Returns

int

The number of rows that matched the WHERE clause and were removed.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var usersTable = schema["users"];

    // Delete inactive users older than one year
    Filter filter = new Filter();
    filter.Add(new Criterion<bool>(usersTable["active"], false));
    filter.Add(new BooleanItem(BooleanType.And));
    filter.Add(new Criterion<DateTime>(usersTable["last_login"], ConditionalType.LessThan, DateTime.Now.AddYears(-1)));

    var delete = new Delete(usersTable, filter);
    int rowsDeleted = m.DeleteRecords(delete);
    Console.WriteLine($"Deleted {rowsDeleted} inactive users");
}

Remarks

As with UpdateRecords(Update), the returned row count lets a guarded delete distinguish "removed" from "no longer matched" — a return of 0 means another caller got there first and nothing was deleted, with no read-then-delete race.

Exceptions

DbException

Thrown when a database error occurs.