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.
DmScope(IDbConnection connection)Parameters
- connection (IDbConnection) - The connection.
Methods
| Method | Summary |
|---|---|
| ForTenant | Reads and writes only a tenant's rows of models with a <c>[DmTenantKey]</c>, and sets it... |
| AllTenants | Reads and writes every tenant's rows of models with a <c>[DmTenantKey]</c>, which a scop... |
| WithUser | Sets the user <c>[DmCreatedBy]</c> and <c>[DmUpdatedBy]</c> record, in place... |
| IncludeDeleted | Reads deleted rows of models with a <c>[DmSoftDelete]</c> too, and updates them with the |
| OnlyDeleted | Reads only the deleted rows of the models a statement reads, and every other model's rows that are n... |
| HardDeleteAsync | Removes a row by its key, even of a model with a <c>[DmSoftDelete]</c>; its token checke... |
| HardDeleteAsync | Removes a row of a model known at run time by its key, even of a model with a <c>[DmSoftDelete |
| HardDeleteByIdAsync | Removes the row with a key, even of a model with a <c>[DmSoftDelete]</c>. |
| HardDeleteByIdAsync | Removes the row of a model known at run time with a key, even of a model with a <c>[DmSoftDele... |
| HardDeleteAsync | Removes the rows that match a condition, deleted or not, of the scope's tenant. |
| HardDeleteAllAsync | Removes every row, deleted or not, of the scope's tenant. |
| HardDeleteAllAsync | Removes every row of a model known at run time, deleted or not, of the scope's tenant. |
| BulkInsertAsync | Inserts rows in bulk, all or none: PostgreSQL's binary <c>COPY</c>, SQL Server's <c&g... |
| BulkInsertAsync | Inserts rows in bulk, all or none, as CancellationToken) does.... |
| BulkInsertAsync | Inserts rows of a model known at run time in bulk, all or none. |
| BulkInsertAsync | Inserts rows of a model known at run time in bulk, all or none. |
| BulkUpsertAsync | Inserts rows in bulk, or updates the rows with their primary keys, all or none. |
| BulkUpsertAsync | Inserts rows in bulk, or updates the rows they conflict with as the options say, all or none. |
| BulkUpsertAsync | Inserts rows of a model known at run time in bulk, or updates the rows with their primary keys, all ... |
| AsCallerAsync | Runs the scope's statements as a caller, held to the policies as the web API holds requests: each ta... |
| InSchema | Uses a schema for every model, such as a tenant's, instead of each model's own. |
| WithTableName | Uses a table for a model, such as an archive table, instead of the model's own. |
| WithTableName | Uses a table for a model, such as an archive table, instead of the model's own. |
| InsertAsync | Inserts a row. |
| InsertAsync | Inserts a row. |
| InsertManyAsync | Inserts rows, several to a statement. |
| InsertManyAsync | Inserts rows, several to a statement. |
| UpdateAsync | Updates every column of a row but its key, by its key. |
| UpdateAsync | Updates every column of a row but its key, by its key. |
| DeleteAsync | Deletes a row, by its key. |
| DeleteAsync | Deletes a row, by its key. |
| DeleteByIdAsync | Deletes the row with a key. |
| DeleteByIdAsync | Deletes the row with a key. |
| SingleByIdAsync | Reads the row with a key. |
| SingleByIdAsync | Reads the row with a key. |
| SelectByIdsAsync | Reads the rows with any of the given keys, in no particular order. |
| SelectByIdsAsync | Reads the rows with any of the given keys, in no particular order. |
| SelectAsync | Reads the rows that match a condition, or every row. |
| SingleAsync | Reads the one row that matches a condition. |
| FirstAsync | Reads the first row that matches a condition, in key order. |
| CountAsync | Counts the rows that match a condition, or every row. |
| ExistsAsync | Tells whether any row matches a condition, or whether the table has any rows. |
| UpdateAsync | Sets columns of the rows that match a condition. |
| DeleteAsync | Deletes the rows that match a condition. |
| DeleteAllAsync | Deletes every row. |
| DeleteAllAsync | Deletes every row. |
| SelectAsync | Reads every row of a model. |
| FirstAsync | Reads the row of a model with the lowest key. |
| CountAsync | Counts the rows of a model. |
| ExistsAsync | Tells whether a model's table has any rows. |
| From | Starts a query of a model's rows, refined with <c>Where</c>, <c>OrderBy</c>,... |
| LoadAsync | Loads relations onto rows already read, by one query per relation and batch of the rows' keys: <c... |
| PatchAsync | Sets the columns a patch has values for, leaving the rest unchanged. |
| PatchAsync | Sets the columns a patch has values for in the row with the key the patch holds, leaving the rest un... |
| UpsertAsync | Inserts a row, or updates every column of the row with its primary key if there is one. |
| UpsertAsync | Inserts a row, or updates the row it conflicts with as the options say. |
| UpsertAsync | Inserts a row, or updates every column of the row with its primary key if there is one. |
| InsertIfAbsentAsync | Inserts a row unless a row with its primary key exists. |
| InsertIfAbsentAsync | Inserts a row unless a row with the same values in some columns exists. |
| InsertIfAbsentAsync | Inserts 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.
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.
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.
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.
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.
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.
Task<int> 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<int>
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>.
Task<int> 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<int>
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>.
Task<int> 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<int>
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>.
Task<int> 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<int>
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.
Task<int> 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<int>
The number of rows removed.
HardDeleteAllAsync
Removes every row, deleted or not, of the scope's tenant.
Task<int> HardDeleteAllAsync(
IDbTransaction tx,
CancellationToken cancellationToken)Parameters
- tx (IDbTransaction) - The transaction to use, or null.
- cancellationToken (CancellationToken) - The cancellation token.
Returns
Type: Task<int>
The number of rows removed.
HardDeleteAllAsync
Removes every row of a model known at run time, deleted or not, of the scope's tenant.
Task<int> 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<int>
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.
Task<long> 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<long>
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.
Task<long> 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<long>
The number of rows inserted.
BulkInsertAsync
Inserts rows of a model known at run time in bulk, all or none.
Task<long> 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<long>
The number of rows inserted.
BulkInsertAsync
Inserts rows of a model known at run time in bulk, all or none.
Task<long> 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<long>
The number of rows inserted.
BulkUpsertAsync
Inserts rows in bulk, or updates the rows with their primary keys, all or none.
Task<long> 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<long>
The number of rows loaded.
BulkUpsertAsync
Inserts rows in bulk, or updates the rows they conflict with as the options say, all or none.
Task<long> 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<long>
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.
Task<long> 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<long>
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.
Task<DmScope> 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.
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.
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.
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.
Task<object?> 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<object?>
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.
Task<object?> 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<object?>
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.
Task<int> 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<int>
The number of rows inserted.
InsertManyAsync
Inserts rows, several to a statement.
Task<int> 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<int>
The number of rows inserted.
UpdateAsync
Updates every column of a row but its key, by its key.
Task<int> 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<int>
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.
Task<int> 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<int>
The number of rows updated: 1, or 0 if no row has the key.
DeleteAsync
Deletes a row, by its key.
Task<int> 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<int>
The number of rows deleted: 1, or 0 if no row has the key.
DeleteAsync
Deletes a row, by its key.
Task<int> 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<int>
The number of rows deleted: 1, or 0 if no row has the key.
DeleteByIdAsync
Deletes the row with a key.
Task<int> 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<int>
The number of rows deleted: 1, or 0 if no row has the key.
DeleteByIdAsync
Deletes the row with a key.
Task<int> 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<int>
The number of rows deleted: 1, or 0 if no row has the key.
SingleByIdAsync
Reads the row with a key.
Task<T?> 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<T?>
The row, or null if there is none.
SingleByIdAsync
Reads the row with a key.
Task<object?> 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<object?>
The row, or null if there is none.
SelectByIdsAsync
Reads the rows with any of the given keys, in no particular order.
Task<List<T>> 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<List<T>>
The rows found.
SelectByIdsAsync
Reads the rows with any of the given keys, in no particular order.
Task<List<object>> 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<List<object>>
The rows found.
SelectAsync
Reads the rows that match a condition, or every row.
Task<List<T>> 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<List<T>>
The rows, in no particular order.
SingleAsync
Reads the one row that matches a condition.
Task<T?> 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<T?>
The row, or null if no row matches.
FirstAsync
Reads the first row that matches a condition, in key order.
Task<T?> 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<T?>
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.
Task<long> 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<long>
The number of rows.
ExistsAsync
Tells whether any row matches a condition, or whether the table has any rows.
Task<bool> 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<bool>
True if a row matches.
UpdateAsync
Sets columns of the rows that match a condition.
Task<int> 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<int>
The number of rows updated; 0 without a round trip if sets nothing.
DeleteAsync
Deletes the rows that match a condition.
Task<int> 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<int>
The number of rows deleted.
DeleteAllAsync
Deletes every row.
Task<int> DeleteAllAsync(IDbTransaction tx, CancellationToken cancellationToken)Parameters
- tx (IDbTransaction) - The transaction to use, or null.
- cancellationToken (CancellationToken) - The cancellation token.
Returns
Type: Task<int>
The number of rows deleted.
DeleteAllAsync
Deletes every row.
Task<int> 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<int>
The number of rows deleted.
SelectAsync
Reads every row of a model.
Task<List<object>> 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<List<object>>
The rows, in no particular order.
FirstAsync
Reads the row of a model with the lowest key.
Task<object?> 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<object?>
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.
Task<long> 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<long>
The number of rows.
ExistsAsync
Tells whether a model's table has any rows.
Task<bool> 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<bool>
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>.
DmQuery<T> 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>.
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.
Task<int> 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<int>
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.
Task<int> 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<int>
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.
Task<object?> 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<object?>
The row's key, as returns it.
UpsertAsync
Inserts a row, or updates the row it conflicts with as the options say.
Task<object?> 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<object?>
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.
Task<object?> 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<object?>
The row's key, as returns it.
InsertIfAbsentAsync
Inserts a row unless a row with its primary key exists.
Task<bool> 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<bool>
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.
Task<bool> 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<bool>
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.
Task<bool> 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<bool>
True if the row was inserted; a key the database generated is then set on it.
GetType
GetType()ToString
ToString()Equals
Equals()GetHashCode
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?