Method UpdateRecords
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
UpdateRecords(Update)
Updates one or more records in a table based on specified criteria.
public int UpdateRecords(Update update)
Parameters
Returns
- int
The number of rows that matched the WHERE clause and were modified.
Examples
using (var m = new Manager(conn))
{
var schema = m.LoadSchema("app");
var usersTable = schema["users"];
// Create an update operation
var update = new Update(usersTable);
update.SetFieldDateTime("last_login", DateTime.Now);
update.AddWhereClause(new Criterion<string>(usersTable["email"], "john@example.com"));
int rowsUpdated = m.UpdateRecords(update);
Console.WriteLine($"Updated {rowsUpdated} rows");
}
Remarks
The returned row count is what makes compare-and-swap possible: pair a guard condition in the WHERE clause with SetFieldAsExpression(ISelectItem, Expression) and a return of 0 tells you the guard failed and nothing was written, without any read-then-write race.
Exceptions
- DbException
Thrown when a database error occurs.