Skip to content

DmScope ​

Namespace: MJCZone.DapperMatic.Dml

Assembly: MJCZone.DapperMatic

Summary ​

The tenant, the user, and which deleted rows a scope reads; and the columns the DML methods fill and filter on their own: <c>[DmSoftDelete]</c>, <c>[DmConcurrencyToken]</c>, <c>[DmCreatedAt]</c>, <c>[DmUpdatedAt]</c>, <c>[DmCreatedBy]</c>, <c>[DmUpdatedBy]</c> and <c>[DmTenantKey]</c>.

sealed public

Contents ​

Constructors (1) | Methods (64) | Properties (3)

Constructors ​

DmScope ​

Initializes a new instance of the DmScope class with no substitutions.

csharp
DmScope(IDbConnection connection)

Parameters ​

  • connection (IDbConnection) - The connection.

Methods ​

MethodSummary
ForTenantReads and writes only a tenant's rows of models with a <c>[DmTenantKey]</c>, and sets it...
AllTenantsReads and writes every tenant's rows of models with a <c>[DmTenantKey]</c>, which a scop...
WithUserSets the user <c>[DmCreatedBy]</c> and <c>[DmUpdatedBy]</c> record, in place...
IncludeDeletedReads deleted rows of models with a <c>[DmSoftDelete]</c> too, and updates them with the
OnlyDeletedReads only the deleted rows of the models a statement reads, and every other model's rows that are n...
HardDeleteAsyncRemoves a row by its key, even of a model with a <c>[DmSoftDelete]</c>; its token checke...
HardDeleteAsyncRemoves a row of a model known at run time by its key, even of a model with a <c>[DmSoftDelete
HardDeleteByIdAsyncRemoves the row with a key, even of a model with a <c>[DmSoftDelete]</c>.
HardDeleteByIdAsyncRemoves the row of a model known at run time with a key, even of a model with a <c>[DmSoftDele...
HardDeleteAsyncRemoves the rows that match a condition, deleted or not, of the scope's tenant.
HardDeleteAllAsyncRemoves every row, deleted or not, of the scope's tenant.
HardDeleteAllAsyncRemoves every row of a model known at run time, deleted or not, of the scope's tenant.
BulkInsertAsyncInserts rows in bulk, all or none: PostgreSQL's binary <c>COPY</c>, SQL Server's <c&g...
BulkInsertAsyncInserts rows in bulk, all or none, as CancellationToken) does....
BulkInsertAsyncInserts rows of a model known at run time in bulk, all or none.
BulkInsertAsyncInserts rows of a model known at run time in bulk, all or none.
BulkUpsertAsyncInserts rows in bulk, or updates the rows with their primary keys, all or none.
BulkUpsertAsyncInserts rows in bulk, or updates the rows they conflict with as the options say, all or none.
BulkUpsertAsyncInserts rows of a model known at run time in bulk, or updates the rows with their primary keys, all ...
AsCallerAsyncRuns the scope's statements as a caller, held to the policies as the web API holds requests: each ta...
InSchemaUses a schema for every model, such as a tenant's, instead of each model's own.
WithTableNameUses a table for a model, such as an archive table, instead of the model's own.
WithTableNameUses a table for a model, such as an archive table, instead of the model's own.
InsertAsyncInserts a row.
InsertAsyncInserts a row.
InsertManyAsyncInserts rows, several to a statement.
InsertManyAsyncInserts rows, several to a statement.
UpdateAsyncUpdates every column of a row but its key, by its key.
UpdateAsyncUpdates every column of a row but its key, by its key.
DeleteAsyncDeletes a row, by its key.
DeleteAsyncDeletes a row, by its key.
DeleteByIdAsyncDeletes the row with a key.
DeleteByIdAsyncDeletes the row with a key.
SingleByIdAsyncReads the row with a key.
SingleByIdAsyncReads the row with a key.
SelectByIdsAsyncReads the rows with any of the given keys, in no particular order.
SelectByIdsAsyncReads the rows with any of the given keys, in no particular order.
SelectAsyncReads the rows that match a condition, or every row.
SingleAsyncReads the one row that matches a condition.
FirstAsyncReads the first row that matches a condition, in key order.
CountAsyncCounts the rows that match a condition, or every row.
ExistsAsyncTells whether any row matches a condition, or whether the table has any rows.
UpdateAsyncSets columns of the rows that match a condition.
DeleteAsyncDeletes the rows that match a condition.
DeleteAllAsyncDeletes every row.
DeleteAllAsyncDeletes every row.
SelectAsyncReads every row of a model.
FirstAsyncReads the row of a model with the lowest key.
CountAsyncCounts the rows of a model.
ExistsAsyncTells whether a model's table has any rows.
FromStarts a query of a model's rows, refined with <c>Where</c>, <c>OrderBy</c>,...
LoadAsyncLoads relations onto rows already read, by one query per relation and batch of the rows' keys: <c...
PatchAsyncSets the columns a patch has values for, leaving the rest unchanged.
PatchAsyncSets the columns a patch has values for in the row with the key the patch holds, leaving the rest un...
UpsertAsyncInserts a row, or updates every column of the row with its primary key if there is one.
UpsertAsyncInserts a row, or updates the row it conflicts with as the options say.
UpsertAsyncInserts a row, or updates every column of the row with its primary key if there is one.
InsertIfAbsentAsyncInserts a row unless a row with its primary key exists.
InsertIfAbsentAsyncInserts a row unless a row with the same values in some columns exists.
InsertIfAbsentAsyncInserts a row unless a row with its primary key exists.
GetType
ToString
Equals
GetHashCode

ForTenant ​

Reads and writes only a tenant's rows of models with a <c>[DmTenantKey]</c>, and sets it on rows inserted.

csharp
DmScope ForTenant(object tenantId)

Parameters ​

  • tenantId (object) - The tenant's id, converted to each tenant key's type.

Returns ​

Type: DmScope

A scope for the tenant.

AllTenants ​

Reads and writes every tenant's rows of models with a <c>[DmTenantKey]</c>, which a scope with no tenant otherwise refuses: for administration and background work.

csharp
DmScope AllTenants()

Returns ​

Type: DmScope

A scope for every tenant.

WithUser ​

Sets the user <c>[DmCreatedBy]</c> and <c>[DmUpdatedBy]</c> record, in place of User.

csharp
DmScope WithUser(object user)

Parameters ​

  • user (object) - The user, converted to each column's type; null for none, which leaves them as they are.

Returns ​

Type: DmScope

A scope for the user.

IncludeDeleted ​

Reads deleted rows of models with a <c>[DmSoftDelete]</c> too, and updates them with the rest.

csharp
DmScope IncludeDeleted()

Returns ​

Type: DmScope

A scope that sees deleted rows.

OnlyDeleted ​

Reads only the deleted rows of the models a statement reads, and every other model's rows that are not deleted.

csharp
DmScope OnlyDeleted()

Returns ​

Type: DmScope

A scope that sees only deleted rows.

HardDeleteAsync ​

Removes a row by its key, even of a model with a <c>[DmSoftDelete]</c>; its token checked and its tenant kept.

csharp
Task&lt;int&gt; HardDeleteAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed: 1, or 0 if no row has the key.

HardDeleteAsync ​

Removes a row of a model known at run time by its key, even of a model with a <c>[DmSoftDelete]</c>.

csharp
Task&lt;int&gt; HardDeleteAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed: 1, or 0 if no row has the key.

HardDeleteByIdAsync ​

Removes the row with a key, even of a model with a <c>[DmSoftDelete]</c>.

csharp
Task&lt;int&gt; HardDeleteByIdAsync(
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • key (object) - takes it.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed: 1, or 0 if no row has the key.

HardDeleteByIdAsync ​

Removes the row of a model known at run time with a key, even of a model with a <c>[DmSoftDelete]</c>.

csharp
Task&lt;int&gt; HardDeleteByIdAsync(
    Type type,
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • key (object) - takes it.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed: 1, or 0 if no row has the key.

HardDeleteAsync ​

Removes the rows that match a condition, deleted or not, of the scope's tenant.

csharp
Task&lt;int&gt; HardDeleteAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - .
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed.

HardDeleteAllAsync ​

Removes every row, deleted or not, of the scope's tenant.

csharp
Task&lt;int&gt; HardDeleteAllAsync(
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed.

HardDeleteAllAsync ​

Removes every row of a model known at run time, deleted or not, of the scope's tenant.

csharp
Task&lt;int&gt; HardDeleteAllAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows removed.

BulkInsertAsync ​

Inserts rows in bulk, all or none: PostgreSQL's binary <c>COPY</c>, SQL Server's <c>SqlBulkCopy</c>, MySqlConnector's <c>MySqlBulkCopy</c>, or on SQLite one prepared statement per row, reached through the connection's own driver; multi-row <c>VALUES</c> where none is available.

csharp
Task&lt;long&gt; BulkInsertAsync(
    IEnumerable{``0} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows, read once, as they are loaded.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows inserted. Keys the database generates are not set on the rows.

BulkInsertAsync ​

Inserts rows in bulk, all or none, as CancellationToken) does.

csharp
Task&lt;long&gt; BulkInsertAsync(
    IEnumerable{``0} rows,
    DmBulkOptions options,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows, read once, as they are loaded.
  • options (DmBulkOptions) - The batch size, the timeout, and what to do without a native path.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows inserted.

BulkInsertAsync ​

Inserts rows of a model known at run time in bulk, all or none.

csharp
Task&lt;long&gt; BulkInsertAsync(
    Type type,
    Object} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • rows (Object}) - The rows, read once, as they are loaded.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows inserted.

BulkInsertAsync ​

Inserts rows of a model known at run time in bulk, all or none.

csharp
Task&lt;long&gt; BulkInsertAsync(
    Type type,
    Object} rows,
    DmBulkOptions options,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • rows (Object}) - The rows, read once, as they are loaded.
  • options (DmBulkOptions) - The batch size, the timeout, and what to do without a native path.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows inserted.

BulkUpsertAsync ​

Inserts rows in bulk, or updates the rows with their primary keys, all or none.

csharp
Task&lt;long&gt; BulkUpsertAsync(
    IEnumerable{``0} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows, read once; no two may have the same key.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows loaded.

BulkUpsertAsync ​

Inserts rows in bulk, or updates the rows they conflict with as the options say, all or none.

csharp
Task&lt;long&gt; BulkUpsertAsync(
    IEnumerable{``0} rows,
    DmUpsertOptions{``0} upsert,
    DmBulkOptions bulk,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows, read once; no two may conflict with each other.
  • upsert (DmUpsertOptions{``0}) - The conflict columns, what to set, and when, as for a single row.
  • bulk (DmBulkOptions) - The batch size, the timeout, and what to do without a native path; null for the defaults.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows loaded.

BulkUpsertAsync ​

Inserts rows of a model known at run time in bulk, or updates the rows with their primary keys, all or none.

csharp
Task&lt;long&gt; BulkUpsertAsync(
    Type type,
    Object} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • rows (Object}) - The rows, read once; no two may have the same key.
  • tx (IDbTransaction) - The transaction to use, or null for one of the method's own.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows loaded.

AsCallerAsync ​

Runs the scope's statements as a caller, held to the policies as the web API holds requests: each table read or written needs a policy granting the action; reads see the rows the policies' filters let through, with columns the caller may not read left empty; writes are held to the filters, checks, presets and columns; related tables (relations, includes, joins) are held to their own policies. Without it, statements run as trusted code.

csharp
Task&lt;DmScope&gt; AsCallerAsync(
    DmAccessContext access,
    DmPolicy} policies,
    string datasourceId,
    CancellationToken cancellationToken)

Parameters ​

  • access (DmAccessContext) - The caller: who they are, their tenant and values.
  • policies (DmPolicy}) - The policies, such as those of the web API.
  • datasourceId (string) - The datasource the policies know the connection by.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task<DmScope>

A scope like this one, run as the caller.

InSchema ​

Uses a schema for every model, such as a tenant's, instead of each model's own.

csharp
DmScope InSchema(string schemaName)

Parameters ​

  • schemaName (string) - The schema.

Returns ​

Type: DmScope

A scope using it.

WithTableName ​

Uses a table for a model, such as an archive table, instead of the model's own.

csharp
DmScope WithTableName(string tableName)

Parameters ​

  • tableName (string) - The table.

Returns ​

Type: DmScope

A scope using it.

WithTableName ​

Uses a table for a model, such as an archive table, instead of the model's own.

csharp
DmScope WithTableName(Type type, string tableName)

Parameters ​

  • type (Type) - The model type.
  • tableName (string) - The table.

Returns ​

Type: DmScope

A scope using it.

InsertAsync ​

Inserts a row.

csharp
Task&lt;object?&gt; InsertAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

        The row's key: the value the database generated for an auto-increment key, which is also set on the row; the
        key the row carries otherwise; or null for a composite key or no key.

InsertAsync ​

Inserts a row.

csharp
Task&lt;object?&gt; InsertAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

        The row's key: the value the database generated for an auto-increment key, which is also set on the row; the
        key the row carries otherwise; or null for a composite key or no key.

InsertManyAsync ​

Inserts rows, several to a statement.

csharp
Task&lt;int&gt; InsertManyAsync(
    IEnumerable{``0} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows inserted.

InsertManyAsync ​

Inserts rows, several to a statement.

csharp
Task&lt;int&gt; InsertManyAsync(
    Type type,
    Object} rows,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • rows (Object}) - The rows.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows inserted.

UpdateAsync ​

Updates every column of a row but its key, by its key.

csharp
Task&lt;int&gt; UpdateAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows updated: 1, or 0 if no row has the key.

UpdateAsync ​

Updates every column of a row but its key, by its key.

csharp
Task&lt;int&gt; UpdateAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows updated: 1, or 0 if no row has the key.

DeleteAsync ​

Deletes a row, by its key.

csharp
Task&lt;int&gt; DeleteAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted: 1, or 0 if no row has the key.

DeleteAsync ​

Deletes a row, by its key.

csharp
Task&lt;int&gt; DeleteAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted: 1, or 0 if no row has the key.

DeleteByIdAsync ​

Deletes the row with a key.

csharp
Task&lt;int&gt; DeleteByIdAsync(
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • key (object) - .

  • tx (IDbTransaction) - The transaction to use, or null.

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted: 1, or 0 if no row has the key.

DeleteByIdAsync ​

Deletes the row with a key.

csharp
Task&lt;int&gt; DeleteByIdAsync(
    Type type,
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.

  • key (object) - .

  • tx (IDbTransaction) - The transaction to use, or null.

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted: 1, or 0 if no row has the key.

SingleByIdAsync ​

Reads the row with a key.

csharp
Task&lt;T?&gt; SingleByIdAsync(
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • key (object) - .

  • tx (IDbTransaction) - The transaction to use, or null.

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;T?&gt;

The row, or null if there is none.

SingleByIdAsync ​

Reads the row with a key.

csharp
Task&lt;object?&gt; SingleByIdAsync(
    Type type,
    object key,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.

  • key (object) - .

  • tx (IDbTransaction) - The transaction to use, or null.

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

The row, or null if there is none.

SelectByIdsAsync ​

Reads the rows with any of the given keys, in no particular order.

csharp
Task&lt;List&lt;T&gt;&gt; SelectByIdsAsync(
    Object} keys,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • keys (Object}) - The keys.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;List&lt;T&gt;&gt;

The rows found.

SelectByIdsAsync ​

Reads the rows with any of the given keys, in no particular order.

csharp
Task&lt;List&lt;object&gt;&gt; SelectByIdsAsync(
    Type type,
    Object} keys,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type, which must have a single-column key.
  • keys (Object}) - The keys.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;List&lt;object&gt;&gt;

The rows found.

SelectAsync ​

Reads the rows that match a condition, or every row.

csharp
Task&lt;List&lt;T&gt;&gt; SelectAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - , or null for every row.
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;List&lt;T&gt;&gt;

The rows, in no particular order.

SingleAsync ​

Reads the one row that matches a condition.

csharp
Task&lt;T?&gt; SingleAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - The condition.
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;T?&gt;

The row, or null if no row matches.

FirstAsync ​

Reads the first row that matches a condition, in key order.

csharp
Task&lt;T?&gt; FirstAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - The condition, or null for any row.
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;T?&gt;

The row with the lowest key that matches, any matching row for a model with no key, or null.

CountAsync ​

Counts the rows that match a condition, or every row.

csharp
Task&lt;long&gt; CountAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - The condition, or null for every row.
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows.

ExistsAsync ​

Tells whether any row matches a condition, or whether the table has any rows.

csharp
Task&lt;bool&gt; ExistsAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - The condition, or null for any row.
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;bool&gt;

True if a row matches.

UpdateAsync ​

Sets columns of the rows that match a condition.

csharp
Task&lt;int&gt; UpdateAsync(
    Func{``0 set,
    ``0}} where,
    Func{``0 tx,
    Boolean}} cancellationToken)

Parameters ​

  • set (Func{``0) - .

  • where (``0}}) - .

  • tx (Func{``0) - The transaction to use, or null.

  • cancellationToken (Boolean}}) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows updated; 0 without a round trip if sets nothing.

DeleteAsync ​

Deletes the rows that match a condition.

csharp
Task&lt;int&gt; DeleteAsync(
    Func{``0 where,
    Boolean}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • where (Func{``0) - .
  • tx (Boolean}}) - The transaction to use, or null.
  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted.

DeleteAllAsync ​

Deletes every row.

csharp
Task&lt;int&gt; DeleteAllAsync(IDbTransaction tx, CancellationToken cancellationToken)

Parameters ​

  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted.

DeleteAllAsync ​

Deletes every row.

csharp
Task&lt;int&gt; DeleteAllAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows deleted.

SelectAsync ​

Reads every row of a model.

csharp
Task&lt;List&lt;object&gt;&gt; SelectAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;List&lt;object&gt;&gt;

The rows, in no particular order.

FirstAsync ​

Reads the row of a model with the lowest key.

csharp
Task&lt;object?&gt; FirstAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

The row with the lowest key, any row for a model with no key, or null if there are none.

CountAsync ​

Counts the rows of a model.

csharp
Task&lt;long&gt; CountAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;long&gt;

The number of rows.

ExistsAsync ​

Tells whether a model's table has any rows.

csharp
Task&lt;bool&gt; ExistsAsync(
    Type type,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;bool&gt;

True if it does.

From ​

Starts a query of a model's rows, refined with <c>Where</c>, <c>OrderBy</c>, <c>Skip</c>, <c>Take</c> and <c>Select</c>.

csharp
DmQuery&lt;T&gt; From()

Returns ​

Type: DmQuery<T>

A query of every row, which runs only when one of its methods is called.

LoadAsync ​

Loads relations onto rows already read, by one query per relation and batch of the rows' keys: <c>LoadAsync(orders, o => o.Include(x => x.Customer).Include(x => x.Lines, l => l.Include(y => y.Product)))</c>.

csharp
Task LoadAsync(
    IEnumerable{``0} rows,
    DmInclude{``0} include,
    DmInclude{``0}} reload,
    bool tx,
    IDbTransaction cancellationToken)

Parameters ​

  • rows (IEnumerable{``0}) - The rows.

  • include (DmInclude{``0}) - .

  • reload (DmInclude{``0}}) - Whether to load a relation onto a row that has it already; by default a relation that is not null is kept.

  • tx (bool) - The transaction to use, or null.

  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task

A task.

PatchAsync ​

Sets the columns a patch has values for, leaving the rest unchanged.

csharp
Task&lt;int&gt; PatchAsync(
    object patch,
    Func{``0 where,
    Boolean}} setNull,
    Func{``0 tx,
    Object}} cancellationToken)

Parameters ​

  • patch (object) - with nullable properties: a null property leaves its column unchanged. A property the model has no column for is an error, not ignored, so that a misspelled one does not silently update nothing.

  • where (Func{``0) - The rows to patch; or null for the row with the key the patch holds. A patch never changes a key.

  • setNull (Boolean}}) - .

  • tx (Func{``0) - The transaction to use, or null.

  • cancellationToken (Object}}) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows patched; 0 without a round trip if the patch sets nothing.

PatchAsync ​

Sets the columns a patch has values for in the row with the key the patch holds, leaving the rest unchanged.

csharp
Task&lt;int&gt; PatchAsync(
    Type type,
    object patch,
    String} setNull,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.

  • patch (object) - Any object whose properties are named as the model's are: a null property leaves its column unchanged, and a property the model has no column for is an error. Its key properties say which row; a patch never changes a key.

  • setNull (String}) - The names of the properties whose columns to set to NULL, or null.

  • tx (IDbTransaction) - The transaction to use, or null.

  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;int&gt;

The number of rows patched: 1, or 0 if no row has the key or the patch sets nothing.

UpsertAsync ​

Inserts a row, or updates every column of the row with its primary key if there is one.

csharp
Task&lt;object?&gt; UpsertAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

The row's key, as returns it.

UpsertAsync ​

Inserts a row, or updates the row it conflicts with as the options say.

csharp
Task&lt;object?&gt; UpsertAsync(
    ``0 row,
    DmUpsertOptions{``0} options,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • options (DmUpsertOptions{``0}) - The conflict columns, what to set, and when.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

        The row's key: for a key the database generates, the inserted row's new key or the conflicting row's key,
        which is also set on the row.

UpsertAsync ​

Inserts a row, or updates every column of the row with its primary key if there is one.

csharp
Task&lt;object?&gt; UpsertAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;object?&gt;

The row's key, as returns it.

InsertIfAbsentAsync ​

Inserts a row unless a row with its primary key exists.

csharp
Task&lt;bool&gt; InsertIfAbsentAsync(
    ``0 row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • row (``0) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;bool&gt;

True if the row was inserted; a key the database generated is then set on it.

InsertIfAbsentAsync ​

Inserts a row unless a row with the same values in some columns exists.

csharp
Task&lt;bool&gt; InsertIfAbsentAsync(
    ``0 row,
    Func{``0 onConflict,
    Object}} tx,
    IDbTransaction cancellationToken)

Parameters ​

  • row (``0) - The row.

  • onConflict (Func{``0) - : the primary key or the columns of a unique constraint or index.

  • tx (Object}}) - The transaction to use, or null.

  • cancellationToken (IDbTransaction) - The cancellation token.

Returns ​

Type: Task&lt;bool&gt;

True if the row was inserted; a key the database generated is then set on it.

InsertIfAbsentAsync ​

Inserts a row unless a row with its primary key exists.

csharp
Task&lt;bool&gt; InsertIfAbsentAsync(
    Type type,
    object row,
    IDbTransaction tx,
    CancellationToken cancellationToken)

Parameters ​

  • type (Type) - The model type.
  • row (object) - The row.
  • tx (IDbTransaction) - The transaction to use, or null.
  • cancellationToken (CancellationToken) - The cancellation token.

Returns ​

Type: Task&lt;bool&gt;

True if the row was inserted; a key the database generated is then set on it.

GetType ​

csharp
GetType()

ToString ​

csharp
ToString()

Equals ​

csharp
Equals()

GetHashCode ​

csharp
GetHashCode()

Properties ​

RunsAsCaller ​

Gets a value indicating whether the scope's statements run as a caller, held to policies.

Type: bool

Connection ​

Gets the connection.

Type: IDbConnection

SchemaName ​

Gets the schema the scope uses for every model, or null for each model's own.

Type: string?