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

81 lines
1.8 KiB
Markdown

# Dynamic Table API
The dynamic table API centers on `DynamicTable` and allows expressive calls like:
```csharp
dynamic users = db.Table("users");
```
## Read Operations
Examples backed by `DynamORM.Tests/Select/DynamicAccessTests.cs`:
```csharp
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`
```csharp
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
```csharp
users.Insert(code: "201", first: "Juri", last: "Gagarin");
users.Insert(values: new
{
code = "202",
first = "Juri",
last = "Gagarin"
});
```
## Update
```csharp
users.Update(id: 1, first: "Yuri", last: "Gagarin");
users.Update(
values: new { first = "Yuri" },
where: new { id = 1 });
```
## Delete
```csharp
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:
```csharp
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`.