Table of Contents

Method AddRecord

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

AddRecord(Record)

Inserts a single record into a table and returns the auto-generated identity value.

public long AddRecord(Record record)

Parameters

record Record

The Record object containing the data to insert.

Returns

long

The auto-generated identity (primary key) value of the inserted record.

Examples

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

    // Create a new record
    var record = new Record(usersTable);
    record.SetFieldVarChar("name", "John Doe");
    record.SetFieldVarChar("email", "john@example.com");
    record.SetFieldDateTime("created_at", DateTime.Now);

    // Insert and get the ID
    long newId = m.AddRecord(record);
    Console.WriteLine($"Inserted record with ID: {newId}");
}

Exceptions

NoValueForNotNullColumnException

Thrown when a required NOT NULL column has no value.

ValueSetForAutoGeneratedColumnException

Thrown when attempting to set a value for an auto-increment column.

DbException

Thrown when a database error occurs.