Files
DynamORM/docs/dynamic-table-api.md
2026-02-26 07:49:08 +01:00

1.8 KiB

Dynamic Table API

The dynamic table API centers on DynamicTable and allows expressive calls like:

dynamic users = db.Table("users");

Read Operations

Examples backed by DynamORM.Tests/Select/DynamicAccessTests.cs:

users.Count(columns: "id");
users.First(columns: "id");
users.Last(columns: "id");
users.Min(columns: "id");
users.Max(columns: "id");
users.Avg(columns: "id");
users.Sum(columns: "id");
users.Scalar(columns: "first", id: 19);
users.Single(id: 19);
users.Query(columns: "first,last", order: "id:desc");

Conditions with DynamicColumn

users.Count(where: new DynamicColumn("id").Greater(100));
users.Count(where: new DynamicColumn("login").Like("Hoyt.%"));
users.Count(where: new DynamicColumn("id").Between(75, 100));
users.Count(where: new DynamicColumn("id").In(75, 99, 100));

Insert

users.Insert(code: "201", first: "Juri", last: "Gagarin");

users.Insert(values: new
{
    code = "202",
    first = "Juri",
    last = "Gagarin"
});

Update

users.Update(id: 1, first: "Yuri", last: "Gagarin");

users.Update(
    values: new { first = "Yuri" },
    where: new { id = 1 });

Delete

users.Delete(code: "201");
users.Delete(where: new { id = 14, code = 14 });

Typed Dynamic Table Calls

DynamicTable methods also accept type: typeof(T) for mapped class scenarios:

users.Count(type: typeof(User), columns: "id");
users.Query(type: typeof(User));

These usage patterns are covered in DynamORM.Tests/Select/TypedAccessTests.cs.

Notes

  • Dynamic member names map to table/column names and builder conventions.
  • Unknown dynamic operations throw InvalidOperationException.
  • Explicit schema behavior depends on DynamicDatabaseOptions.SupportSchema.