Table of Contents

Class Record

Namespace
YndigoBlue.Velocity.Model
Assembly
YndigoBlue.Velocity.dll

Represents a database record for INSERT and UPDATE operations. A Record contains field values that will be persisted to a specific table, with support for literal values, subqueries, and database functions.

public class Record : Datum
Inheritance
Record
Derived

Remarks

Records are created from a Table object and automatically inherit the table's column structure. You set field values using type-specific setter methods (SetFieldString, SetFieldInt, etc.) inherited from Datum.

Auto-generated columns (typically auto-incrementing primary keys) do not need values set and will be populated by the database during insertion.

Examples

Basic record creation and insertion:

using (Manager manager = new Manager(connection))
{
    Schema schema = manager.LoadSchema("my_schema");
    Table usersTable = schema["users"];

    // Create a new record
    Record record = new Record(usersTable);
    record.SetFieldString("username", "john_doe");
    record.SetFieldString("email", "john@example.com");
    record.SetFieldInt("age", 30);
    record.SetFieldDateTime("created_at", DateTime.UtcNow);

    // Insert the record
    manager.AddRecord(record);
}

Using subqueries for field values:

// Create a query to get the max price from products
Query maxPriceQuery = new Query()
    .Select(new Max(productsTable["price"]))
    .From(productsTable);

// Use the subquery result as a field value
Record record = new Record(settingsTable);
record.SetFieldString("setting_name", "max_price");
record.SetFieldAsQuery("setting_value", maxPriceQuery);

manager.AddRecord(record);
// SQL: INSERT INTO settings (setting_name, setting_value)
//      VALUES ('max_price', (SELECT MAX(price) FROM products))

Using database functions for field values:

Record record = new Record(usersTable);
record.SetFieldString("username", "john_doe");

// Use UPPER() function to convert text to uppercase
record.SetFieldAsFunction("display_name", new Upper(new Literal<string>("john doe")));

// Use NOW() for timestamp
record.SetFieldAsFunction("created_at", new Now());

manager.AddRecord(record);

Constructors

Record(Table)

Creates a new record for the specified table.

Properties

FieldCount

Gets the number of fields (columns) available in this datum.

Fields

Gets the collection of select items (columns) that define the structure of this datum.

Table

Gets the table that this record belongs to.

Methods

GetFieldAsFunction(string)

Gets the database function associated with a field.

GetFieldAsFunction(ISelectItem)

Gets the database function associated with a field.

GetFieldAsQuery(string)

Gets the subquery associated with a field.

GetFieldAsQuery(ISelectItem)

Gets the subquery associated with a field.

HasFieldAsFunction(ISelectItem)

Determines whether a field is set to a function value.

HasFieldAsQuery(ISelectItem)

Determines whether a field is set to a subquery value.

SetFieldAsFunction(string, Function)

Sets a field value to be calculated using a database function.

SetFieldAsFunction(ISelectItem, Function)

Sets a field value to be calculated using a database function.

SetFieldAsQuery(string, Query)

Sets a field value to be populated from a subquery result.

SetFieldAsQuery(ISelectItem, Query)

Sets a field value to be populated from a subquery result.