Table of Contents

Class Record<T>

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

Represents a typed database record that supports automatic data binding between C# objects and database columns.

public class Record<T> : Record

Type Parameters

T

The C# type to bind to database columns.

Inheritance
Record<T>

Examples

Snake case binding (most common):

// C# class with PascalCase properties
public class User
{
    public string UserName { get; set; }
    public string EmailAddress { get; set; }
    public int AccountAge { get; set; }
    public DateTime CreatedAt { get; set; }
}

// Database table with snake_case columns
Table usersTable = schema.CreateTable("users");
usersTable.AddColumn("user_name", DataType.VarChar, size: 100);
usersTable.AddColumn("email_address", DataType.VarChar, size: 200);
usersTable.AddColumn("account_age", DataType.Integer);
usersTable.AddColumn("created_at", DataType.DateTime);

var user = new User
{
    UserName = "john_doe",
    EmailAddress = "john@example.com",
    AccountAge = 30,
    CreatedAt = DateTime.UtcNow
};

// Automatically maps properties to columns
Record<User> record = new Record<User>(usersTable, BindingType.SnakeCase);
record.Bind(user);

manager.AddRecord(record);

Attribute-based binding for custom mapping:

using YndigoBlue.Velocity.Attributes;

public class Employee
{
    [Column("emp_id")]
    public int EmployeeId { get; set; }

    [Column("first_name")]
    public string FirstName { get; set; }

    [Column("last_name")]
    public string LastName { get; set; }

    // This property won't be mapped
    public string FullName => $"{FirstName} {LastName}";
}

var employee = new Employee
{
    EmployeeId = 1,
    FirstName = "John",
    LastName = "Doe"
};

Record<Employee> record = new Record<Employee>(employeesTable, BindingType.Attribute);
record.Bind(employee);

manager.AddRecord(record);

Bulk insert with binding:

List<User> users = GetUsersFromApi();

using (Manager manager = new Manager(connection))
{
    manager.BeginTransaction();
    try
    {
        foreach (var user in users)
        {
            Record<User> record = new Record<User>(usersTable, BindingType.SnakeCase);
            record.Bind(user);
            manager.AddRecord(record);
        }
        manager.CommitTransaction();
    }
    catch
    {
        manager.RollbackTransaction();
        throw;
    }
}

Remarks

Record<T> eliminates the need to manually set each field by automatically mapping properties from a C# object to database columns using configurable binding strategies.

Binding strategies include:

  • SnakeCaseConverts PascalCase/camelCase to snake_case (UserName → user_name)
  • CamelCaseConverts PascalCase to camelCase (UserName → userName)
  • DirectMapDirect 1:1 property name to column name mapping
  • AttributeUses [Column] attributes for custom mapping

Constructors

Record(Table, BindingType)

Creates a new typed record for the specified table with the specified binding strategy.

Methods

Bind(T)

Binds a C# object to this record by automatically mapping properties to database columns using the configured binding strategy.