Table of Contents

Class DataContextExtensions

Namespace
NextORM.Core
Assembly
nextorm.core.dll

Provider-independent helpers and convenience overloads for IDataContext. These used to be default interface methods; keeping them outside the interface leaves the provider-implemented contract (the role interfaces) free of engine-independent behavior.

public static class DataContextExtensions
Inheritance
DataContextExtensions
Inherited Members

Methods

Any(IDataContext, IPreparedQueryCommand<bool>, params ReadOnlySpan<object?>)

Synchronously determines whether the query produces at least one row.

public static bool Any(this IDataContext dataContext, IPreparedQueryCommand<bool> preparedQueryCommand, params ReadOnlySpan<object?> @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<bool>

The prepared query to evaluate.

params ReadOnlySpan<object>

Positional parameter values, in the order the SQL references them.

Returns

bool

true when at least one row matches; otherwise false.

AnyAsync(IDataContext, IPreparedQueryCommand<bool>, params object[]?)

Asynchronously determines whether the query produces at least one row.

public static Task<bool> AnyAsync(this IDataContext dataContext, IPreparedQueryCommand<bool> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<bool>

The prepared query to evaluate.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<bool>

true when at least one row matches; otherwise false.

AnyAsync(IDataContext, IPreparedQueryCommand<bool>, object[]?, CancellationToken)

Asynchronously determines whether the query produces at least one row. Stops after the first matching row rather than materializing the full result.

public static Task<bool> AnyAsync(this IDataContext dataContext, IPreparedQueryCommand<bool> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<bool>

The prepared query to evaluate.

params object[]

Positional parameter values, in the order the SQL references them.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

Task<bool>

true when at least one row matches; otherwise false.

AnyAsync(IDataContext, IPreparedQueryCommand<bool>, CancellationToken)

Asynchronously determines whether the query produces at least one row, using no parameters.

public static Task<bool> AnyAsync(this IDataContext dataContext, IPreparedQueryCommand<bool> preparedQueryCommand, CancellationToken cancellationToken)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<bool>

The prepared query to evaluate.

cancellationToken CancellationToken

Token used to cancel the operation.

Returns

Task<bool>

true when at least one row matches; otherwise false.

CreateBulkInsertBuilder<TEntity>(IDataContext, BulkInsertOptions, Action<EntityMetadataBuilder<TEntity>>?)

Starts a bulk insert with explicit BulkInsertOptions. The type's metadata is resolved lazily and cached per process, exactly like CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?); the write uses the provider's native bulk API where one exists and a chunked parameterised INSERT ... VALUES otherwise. The options shape the statement (batch limits, identity, conflict handling, timeout and progress).

public static BulkInsertBuilder<TEntity> CreateBulkInsertBuilder<TEntity>(this IDataContext dataContext, BulkInsertOptions options, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

options BulkInsertOptions

The write options.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

BulkInsertBuilder<TEntity>

A builder for the bulk insert.

Type Parameters

TEntity

The mapped entity type to write.

Exceptions

ArgumentNullException

options is null.

ArgumentOutOfRangeException

An option value is not positive.

CreateBulkInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts a bulk insert over the mapping of TEntity and returns its fluent builder. The type's metadata is resolved lazily and cached per process, exactly like CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?); configEntity therefore runs only on the first call for TEntity. The write uses the provider's native bulk API where one exists and a chunked parameterised INSERT ... VALUES otherwise.

public static BulkInsertBuilder<TEntity> CreateBulkInsertBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

BulkInsertBuilder<TEntity>

A builder for the bulk insert.

Type Parameters

TEntity

The mapped entity type to write.

CreateBulkInsertBuilder<TEntity>(IDataContext, Func<BulkInsertOptionsBuilder, BulkInsertOptionsBuilder>, Action<EntityMetadataBuilder<TEntity>>?)

Starts a bulk insert configured with the fluent BulkInsertOptionsBuilder. The type's metadata is resolved lazily and cached per process, exactly like CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?). The callback must be an expression lambda that returns the builder (for example o => o.MaxBatchSize(1_000)), which keeps it distinct from the EntityMetadataBuilder<T> overload.

public static BulkInsertBuilder<TEntity> CreateBulkInsertBuilder<TEntity>(this IDataContext dataContext, Func<BulkInsertOptionsBuilder, BulkInsertOptionsBuilder> configure, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configure Func<BulkInsertOptionsBuilder, BulkInsertOptionsBuilder>

Configures the write options; the returned builder is ignored.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

BulkInsertBuilder<TEntity>

A builder for the bulk insert.

Type Parameters

TEntity

The mapped entity type to write.

Exceptions

ArgumentNullException

configure is null.

CreateCommand<T>(IDataContext, QueryDefinition)

Creates a typed query command from a QueryDefinition. This is the single factory the builders use; it replaces the previous overloads that took the whole query shape as a long parameter list.

public static QueryCommand<T> CreateCommand<T>(this IDataContext dataContext, QueryDefinition definition)

Parameters

dataContext IDataContext
definition QueryDefinition

Returns

QueryCommand<T>

Type Parameters

T

CreateDeleteBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts a DELETE over the mapping of TEntity and returns its fluent builder. The type's metadata is resolved lazily and cached per process, exactly like From<T>(); configEntity therefore runs only on the first call for TEntity.

public static DeleteBuilder<TEntity> CreateDeleteBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

DeleteBuilder<TEntity>

A builder for the delete.

Type Parameters

TEntity

The mapped entity type whose rows are deleted.

CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>)

Starts the row-returning multi-table DELETE over the join of query: the target is the first table of the chain and the returned values may read the joined tables. Only INNER Join joins are supported; outer/cross joins are rejected. PostgreSQL renders DELETE ... USING ... RETURNING; every other provider rejects the returning form. The whole-projection (identity) form returns every returnable mapped property of every item slot, in slot order. Consumed through Returning() or Returning<TResult>(Expression<Func<TProjection, TResult>>).

public static DeleteJoinBuilder<Projection<T1, T2>> CreateDeleteJoinBuilder<T1, T2>(this JoinedEntityBuilder<T1, T2> query)

Parameters

query JoinedEntityBuilder<T1, T2>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted (the first table).

T2

The joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3>(JoinedEntityBuilder<T1, T2, T3>)

Starts the row-returning multi-table DELETE over a three-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3>> CreateDeleteJoinBuilder<T1, T2, T3>(this JoinedEntityBuilder<T1, T2, T3> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3, T4>(JoinedEntityBuilder<T1, T2, T3, T4>)

Starts the row-returning multi-table DELETE over a four-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3, T4>> CreateDeleteJoinBuilder<T1, T2, T3, T4>(this JoinedEntityBuilder<T1, T2, T3, T4> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3, T4>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3, T4, T5>(JoinedEntityBuilder<T1, T2, T3, T4, T5>)

Starts the row-returning multi-table DELETE over a five-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5>> CreateDeleteJoinBuilder<T1, T2, T3, T4, T5>(this JoinedEntityBuilder<T1, T2, T3, T4, T5> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>)

Starts the row-returning multi-table DELETE over a six-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6>> CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6, T7>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>)

Starts the row-returning multi-table DELETE over a seven-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7>> CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6, T7>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6, T7, T8>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>)

Starts the row-returning multi-table DELETE over an eight-table join. See CreateDeleteJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7, T8>> CreateDeleteJoinBuilder<T1, T2, T3, T4, T5, T6, T7, T8>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>

The joined query selecting the rows to delete.

Returns

DeleteJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7, T8>>

A builder for the returned-row selector.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

T8

The eighth joined entity type.

CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts an INSERT over the mapping of TEntity and returns its fluent builder. The type's metadata is resolved lazily and cached per process, exactly like From<T>(); configEntity therefore runs only on the first call for TEntity (declare keys/identity/computed columns there or with attributes).

public static InsertBuilder<TEntity> CreateInsertBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

InsertBuilder<TEntity>

A builder for the insert.

Type Parameters

TEntity

The mapped entity type to insert.

CreateMergeBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts a key upsert over the mapping of TEntity and returns its fluent builder. The source row set is supplied with Using and the match key with OnKeys; the statement is rendered as INSERT ... ON CONFLICT ... DO UPDATE, INSERT ... ON DUPLICATE KEY UPDATE or MERGE depending on the provider. Like CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?), the type's metadata is resolved lazily and cached per process, so configEntity runs only on the first call for TEntity.

public static MergeBuilder<TEntity> CreateMergeBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

MergeBuilder<TEntity>

A builder for the key upsert.

Type Parameters

TEntity

The mapped entity type upserted.

CreateQueryBuilder(IDataContext, string)

Explicit factory alias of From(IDataContext, string): starts a query against a raw table (or CTE) name.

public static EntityBuilder<TableAlias> CreateQueryBuilder(this IDataContext dataContext, string table)

Parameters

dataContext IDataContext

The context to execute against.

table string

The table or CTE name.

Returns

EntityBuilder<TableAlias>

A builder for composing the query.

CreateQueryBuilder(IDataContext, string, Action<FromOptions>)

Explicit factory alias of From(IDataContext, string, Action<FromOptions>): starts a query against a raw table (or CTE) name with per-query source options.

public static EntityBuilder<TableAlias> CreateQueryBuilder(this IDataContext dataContext, string table, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

table string

The table or CTE name.

options Action<FromOptions>

Configures the primary source.

Returns

EntityBuilder<TableAlias>

A builder for composing the query.

CreateQueryBuilderFromSql(IDataContext, string, object?)

Explicit factory alias of FromSql(IDataContext, string, object?): starts a query from a raw SQL fragment used as a composable FROM source.

public static EntityBuilder<TableAlias> CreateQueryBuilderFromSql(this IDataContext dataContext, string sql, object? parameters = null)

Parameters

dataContext IDataContext

The context to execute against.

sql string

The raw SQL fragment.

parameters object

An object whose public properties become the named parameters.

Returns

EntityBuilder<TableAlias>

A builder for composing the query.

CreateQueryBuilder<TResult>(IDataContext, EntityBuilder<TResult>)

Explicit factory alias of From<TResult>(IDataContext, EntityBuilder<TResult>): starts a new builder sharing an existing builder's source and definition.

public static EntityBuilder<TResult> CreateQueryBuilder<TResult>(this IDataContext dataContext, EntityBuilder<TResult> builder)

Parameters

dataContext IDataContext

The context to execute against.

builder EntityBuilder<TResult>

The builder to copy the query shape from.

Returns

EntityBuilder<TResult>

A new builder bound to dataContext.

Type Parameters

TResult

The projected element type.

CreateQueryBuilder<TResult>(IDataContext, EntityBuilder<TResult>, Action<FromOptions>)

Explicit factory alias of From<TResult>(IDataContext, EntityBuilder<TResult>, Action<FromOptions>): starts a new builder sharing an existing builder's source and definition, with per-source options.

public static EntityBuilder<TResult> CreateQueryBuilder<TResult>(this IDataContext dataContext, EntityBuilder<TResult> builder, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

builder EntityBuilder<TResult>

The builder to copy the query shape from.

options Action<FromOptions>

Configures the derived-table source.

Returns

EntityBuilder<TResult>

A new builder bound to dataContext.

Type Parameters

TResult

The projected element type.

CreateQueryBuilder<TResult>(IDataContext, QueryCommand<TResult>)

Explicit factory alias of From<TResult>(IDataContext, QueryCommand<TResult>): starts a query from an existing command's definition.

public static EntityBuilder<TResult> CreateQueryBuilder<TResult>(this IDataContext dataContext, QueryCommand<TResult> query)

Parameters

dataContext IDataContext

The context to execute against.

query QueryCommand<TResult>

The command whose definition drives the query.

Returns

EntityBuilder<TResult>

A builder for composing the query further.

Type Parameters

TResult

The projected element type.

CreateQueryBuilder<TResult>(IDataContext, QueryCommand<TResult>, Action<FromOptions>)

Explicit factory alias of From<TResult>(IDataContext, QueryCommand<TResult>, Action<FromOptions>): starts a query from an existing command's definition with per-source options.

public static EntityBuilder<TResult> CreateQueryBuilder<TResult>(this IDataContext dataContext, QueryCommand<TResult> query, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

query QueryCommand<TResult>

The command whose definition drives the query.

options Action<FromOptions>

Configures the derived-table source.

Returns

EntityBuilder<TResult>

A builder for composing the query further.

Type Parameters

TResult

The projected element type.

CreateQueryBuilder<TResult>(IDataContext, TempTableSource<TResult>)

Explicit factory alias of From<TResult>(IDataContext, TempTableSource<TResult>): starts a query over a lazy temporary table.

public static EntityBuilder<TableAlias> CreateQueryBuilder<TResult>(this IDataContext dataContext, TempTableSource<TResult> tempTable)

Parameters

dataContext IDataContext

The context to execute against.

tempTable TempTableSource<TResult>

The lazy source to materialise and read.

Returns

EntityBuilder<TableAlias>

A builder for composing the query over the temporary table.

Type Parameters

TResult

The source query's projected row type.

CreateQueryBuilder<T>(IDataContext, Action<EntityMetadataBuilder<T>>?)

Explicit factory alias of From<T>(IDataContext, Action<EntityMetadataBuilder<T>>?): starts a query over the mapping of T.

public static EntityBuilder<T> CreateQueryBuilder<T>(this IDataContext dataContext, Action<EntityMetadataBuilder<T>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<T>>

Optional mapping configuration, run only when the type is first mapped.

Returns

EntityBuilder<T>

A builder for composing the query.

Type Parameters

T

The mapped entity type.

CreateQueryBuilder<T>(IDataContext, Action<FromOptions>, Action<EntityMetadataBuilder<T>>?)

Explicit factory alias of From<T>(IDataContext, Action<FromOptions>, Action<EntityMetadataBuilder<T>>?): starts a query over the mapping of T with per-query source options.

public static EntityBuilder<T> CreateQueryBuilder<T>(this IDataContext dataContext, Action<FromOptions> options, Action<EntityMetadataBuilder<T>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

options Action<FromOptions>

Configures the primary source.

configEntity Action<EntityMetadataBuilder<T>>

Optional mapping configuration, run only when the type is first mapped.

Returns

EntityBuilder<T>

A builder for composing the query.

Type Parameters

T

The mapped entity type.

CreateSqliteFts5CommandBuilder(IDataContext, string)

Starts a SQLite FTS5 maintenance/control command over a raw FTS5 table name. The returned builder selects one operation (automerge, crisismerge, merge, optimize, rebuild or integrity-check) and then renders or executes it through the FTS5 control interface; providers without FTS5 reject it with NotSupportedException. The table name is preserved verbatim (no trimming or splitting; a dot is a literal character).

public static SqliteFts5CommandBuilder CreateSqliteFts5CommandBuilder(this IDataContext dataContext, string tableName)

Parameters

dataContext IDataContext

The context to execute against.

tableName string

The raw FTS5 table name; must be non-null and not empty/whitespace, and must not contain a NUL character.

Returns

SqliteFts5CommandBuilder

A builder for the FTS5 maintenance command.

Exceptions

ArgumentNullException

dataContext or tableName is null.

ArgumentException

tableName is empty, all whitespace, or contains a NUL character.

CreateTruncateBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts a TRUNCATE TABLE over the mapping of TEntity and returns its terminal. Resets the table faster than CreateDeleteBuilder<T>().All(); providers without a native TRUNCATE (SQLite) reject it.

public static TruncateBuilder<TEntity> CreateTruncateBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

TruncateBuilder<TEntity>

A builder for the truncate.

Type Parameters

TEntity

The mapped entity type whose table is truncated.

CreateUpdateBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?)

Starts an UPDATE over the mapping of TEntity and returns its fluent builder. Add the written columns with Set and the row filter with Where; omitting Where updates every row. Like CreateInsertBuilder<TEntity>(IDataContext, Action<EntityMetadataBuilder<TEntity>>?), the type's metadata is resolved lazily and cached per process, so configEntity runs only on the first call for TEntity.

public static UpdateBuilder<TEntity> CreateUpdateBuilder<TEntity>(this IDataContext dataContext, Action<EntityMetadataBuilder<TEntity>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

configEntity Action<EntityMetadataBuilder<TEntity>>

Optional mapping configuration, run only when the type is first mapped.

Returns

UpdateBuilder<TEntity>

A builder for the update.

Type Parameters

TEntity

The mapped entity type to update.

CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>)

Starts a multi-table UPDATE over the join of query: the target is the first table of the chain and the SET values may read the joined tables. Only INNER Join joins are supported; outer/cross joins are rejected because folding the join conditions into the filter would change which rows are updated. PostgreSQL and SQLite render UPDATE ... FROM; SQL Server renders UPDATE <alias> ... FROM ... JOIN; MySQL/MariaDB render UPDATE ... JOIN ... SET. ClickHouse and the in-memory provider reject it.

public static UpdateJoinBuilder<Projection<T1, T2>> CreateUpdateJoinBuilder<T1, T2>(this JoinedEntityBuilder<T1, T2> query)

Parameters

query JoinedEntityBuilder<T1, T2>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated (the first table).

T2

The joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3>(JoinedEntityBuilder<T1, T2, T3>)

Starts a multi-table UPDATE over a three-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3>> CreateUpdateJoinBuilder<T1, T2, T3>(this JoinedEntityBuilder<T1, T2, T3> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3, T4>(JoinedEntityBuilder<T1, T2, T3, T4>)

Starts a multi-table UPDATE over a four-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3, T4>> CreateUpdateJoinBuilder<T1, T2, T3, T4>(this JoinedEntityBuilder<T1, T2, T3, T4> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3, T4>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3, T4, T5>(JoinedEntityBuilder<T1, T2, T3, T4, T5>)

Starts a multi-table UPDATE over a five-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5>> CreateUpdateJoinBuilder<T1, T2, T3, T4, T5>(this JoinedEntityBuilder<T1, T2, T3, T4, T5> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>)

Starts a multi-table UPDATE over a six-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6>> CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6, T7>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>)

Starts a multi-table UPDATE over a seven-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7>> CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6, T7>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6, T7, T8>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>)

Starts a multi-table UPDATE over an eight-table join. See CreateUpdateJoinBuilder<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7, T8>> CreateUpdateJoinBuilder<T1, T2, T3, T4, T5, T6, T7, T8>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>

The joined query selecting the rows to update.

Returns

UpdateJoinBuilder<Projection<T1, T2, T3, T4, T5, T6, T7, T8>>

A builder for the assignments and the filter.

Type Parameters

T1

The target entity type whose rows are updated.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

T8

The eighth joined entity type.

DeleteAsync<TEntity>(IDataContext, TEntity, CancellationToken)

Asynchronously deletes the row identified by the declared key of entity in one command, using the mapping's [Key]/.Key().

public static Task<int> DeleteAsync<TEntity>(this IDataContext dataContext, TEntity entity, CancellationToken cancellationToken = default)

Parameters

dataContext IDataContext

The context to execute against.

entity TEntity

The entity whose key identifies the row to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows (0 or 1).

Type Parameters

TEntity

The mapped entity type.

Exceptions

InvalidOperationException

The entity type declares no key.

DeleteAsync<T1, T2>(JoinedEntityBuilder<T1, T2>, CancellationToken)

Asynchronously deletes the rows of the first table matching the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2>(this JoinedEntityBuilder<T1, T2> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3>(JoinedEntityBuilder<T1, T2, T3>, CancellationToken)

Asynchronously deletes the rows of the first table of a three-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3>(this JoinedEntityBuilder<T1, T2, T3> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3, T4>(JoinedEntityBuilder<T1, T2, T3, T4>, CancellationToken)

Asynchronously deletes the rows of the first table of a four-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3, T4>(this JoinedEntityBuilder<T1, T2, T3, T4> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3, T4, T5>(JoinedEntityBuilder<T1, T2, T3, T4, T5>, CancellationToken)

Asynchronously deletes the rows of the first table of a five-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3, T4, T5>(this JoinedEntityBuilder<T1, T2, T3, T4, T5> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3, T4, T5, T6>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>, CancellationToken)

Asynchronously deletes the rows of the first table of a six-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3, T4, T5, T6>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3, T4, T5, T6, T7>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>, CancellationToken)

Asynchronously deletes the rows of the first table of a seven-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3, T4, T5, T6, T7>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

DeleteAsync<T1, T2, T3, T4, T5, T6, T7, T8>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>, CancellationToken)

Asynchronously deletes the rows of the first table of an eight-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static Task<int> DeleteAsync<T1, T2, T3, T4, T5, T6, T7, T8>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8> query, CancellationToken cancellationToken = default)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>

The joined query selecting the rows to delete.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

T8

The eighth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<TEntity>(IDataContext, TEntity)

Deletes the row identified by the declared key of entity in one command (DELETE FROM ... WHERE <pk> = @p), using the mapping's [Key]/.Key().

public static int Delete<TEntity>(this IDataContext dataContext, TEntity entity)

Parameters

dataContext IDataContext

The context to execute against.

entity TEntity

The entity whose key identifies the row to delete.

Returns

int

The number of deleted rows (0 or 1).

Type Parameters

TEntity

The mapped entity type.

Exceptions

InvalidOperationException

The entity type declares no key.

Delete<T1, T2>(JoinedEntityBuilder<T1, T2>)

Deletes every row of the first table of a join that matches the join — a native multi-table DELETE. The join condition (and any Where added to the joined builder) selects the rows to remove. Only INNER Join joins are supported; outer/cross joins are rejected because they change which rows are deleted. PostgreSQL renders DELETE ... USING; SQL Server, MySQL and MariaDB render DELETE <alias> FROM ... JOIN. SQLite, ClickHouse and the in-memory provider throw NotSupportedException.

public static int Delete<T1, T2>(this JoinedEntityBuilder<T1, T2> query)

Parameters

query JoinedEntityBuilder<T1, T2>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows, as reported by the provider.

Type Parameters

T1

The target entity type whose rows are deleted (the first table).

T2

The joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE (SQLite, ClickHouse, in-memory), or a join is not an INNER Join.

Delete<T1, T2, T3>(JoinedEntityBuilder<T1, T2, T3>)

Deletes every row of the first table of a three-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3>(this JoinedEntityBuilder<T1, T2, T3> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<T1, T2, T3, T4>(JoinedEntityBuilder<T1, T2, T3, T4>)

Deletes every row of the first table of a four-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3, T4>(this JoinedEntityBuilder<T1, T2, T3, T4> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<T1, T2, T3, T4, T5>(JoinedEntityBuilder<T1, T2, T3, T4, T5>)

Deletes every row of the first table of a five-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3, T4, T5>(this JoinedEntityBuilder<T1, T2, T3, T4, T5> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<T1, T2, T3, T4, T5, T6>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>)

Deletes every row of the first table of a six-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3, T4, T5, T6>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<T1, T2, T3, T4, T5, T6, T7>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>)

Deletes every row of the first table of a seven-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3, T4, T5, T6, T7>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

Delete<T1, T2, T3, T4, T5, T6, T7, T8>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>)

Deletes every row of the first table of an eight-table join that matches the join. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static int Delete<T1, T2, T3, T4, T5, T6, T7, T8>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>

The joined query selecting the rows to delete.

Returns

int

The number of deleted rows.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

T8

The eighth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ExecuteProcedureAsync(IDataContext, string, CancellationToken)

Asynchronously executes a stored procedure without parameters. Convenience overload of ExecuteProcedureAsync(string, IReadOnlyList<ProcedureParameter>, CancellationToken).

public static Task<ProcedureResult> ExecuteProcedureAsync(this IDataContext dataContext, string name, CancellationToken cancellationToken = default)

Parameters

dataContext IDataContext

The context to execute against.

name string

The procedure name, passed to the provider as-is.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<ProcedureResult>

A task producing the result, which must be disposed to release the reader and command.

Exceptions

NotSupportedException

The context does not support stored procedures.

ExecuteRawAsync(IDataContext, string, CancellationToken)

Asynchronously executes a raw command text without parameters. Convenience overload of ExecuteRawAsync(string, IReadOnlyList<ProcedureParameter>, CancellationToken).

public static Task<ProcedureResult> ExecuteRawAsync(this IDataContext dataContext, string sql, CancellationToken cancellationToken = default)

Parameters

dataContext IDataContext

The context to execute against.

sql string

The command text to execute.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<ProcedureResult>

A task producing the result, which must be disposed to release the reader and command.

Exceptions

NotSupportedException

The context does not support raw SQL execution.

FirstAsync<TResult>(IDataContext, IPreparedQueryCommand<TResult>, params object[]?)

Asynchronously returns the first row of the query.

public static Task<TResult> FirstAsync<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<TResult>

The first materialized row.

Type Parameters

TResult

The projected element type.

Exceptions

InvalidOperationException

The query returns no rows.

FirstOrDefaultAsync<TResult>(IDataContext, IPreparedQueryCommand<TResult>, params object[]?)

Asynchronously returns the first row of the query, or the default value of TResult when the query returns no rows.

public static Task<TResult?> FirstOrDefaultAsync<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<TResult>

The first materialized row, or default when there are none.

Type Parameters

TResult

The projected element type.

From(IDataContext, string)

Starts a query against a raw table (or CTE) name. Needed when the context is used through IDataContext and therefore has no concrete From(string) instance method.

Columns are read through TableAlias accessors (t.GetInt64("id") / t["id"].AsInt). The returned builder is generic so that the full operator set (Where/Join/GroupBy/Having/OrderBy/ Limit/Select) is available, unlike the previous non-generic shape.

public static EntityBuilder<TableAlias> From(this IDataContext dataContext, string table)

Parameters

dataContext IDataContext
table string

Returns

EntityBuilder<TableAlias>

Exceptions

ArgumentNullException

table is null.

ArgumentException

table is empty or consists only of white-space characters.

From(IDataContext, string, Action<FromOptions>)

Starts a query against a raw table (or CTE) name with per-query source options (a TABLESAMPLE percentage, a ClickHouse SAMPLE ratio, or per-source table/index hints). Columns are read through TableAlias accessors.

public static EntityBuilder<TableAlias> From(this IDataContext dataContext, string table, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

table string

The table or CTE name.

options Action<FromOptions>

Configures the primary source, for example o => o.TableSample(10) or o => o.WithTableHint("nolock").

Returns

EntityBuilder<TableAlias>

A builder for composing the query.

Exceptions

ArgumentNullException

table is null.

ArgumentException

table is empty or consists only of white-space characters.

FromSql(IDataContext, string, object?)

Starts a query from a raw SQL fragment used as a composable FROM source: it is rendered as (<sql>) AS alias and can be filtered, joined, projected, grouped and paged further. Columns are read through TableAlias accessors (t["id"].AsInt). parameters is an object whose public properties become the named parameters referenced by the SQL (the same convention as WithSql). Requires a provider that supports a derived-table FROM source (SupportsRawSqlSource).

public static EntityBuilder<TableAlias> FromSql(this IDataContext dataContext, string sql, object? parameters = null)

Parameters

dataContext IDataContext
sql string
parameters object

Returns

EntityBuilder<TableAlias>

Exceptions

NotSupportedException

The active provider reports SupportsRawSqlSource as false, or the context is the in-memory provider (which cannot evaluate raw SQL).

From<TResult>(IDataContext, CteReference<TResult>)

Starts the self-referencing read of a recursive common table expression inside the step callback of AsRecursiveCte. The returned builder reads the CTE by its declared name and resolves member access against the anchor's projection shape. A reference is only valid while its owning step callback runs; using a captured or foreign reference (owner mismatch, even under the same name) throws before any database command is built.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, CteReference<TResult> reference)

Parameters

dataContext IDataContext

The context to execute against.

reference CteReference<TResult>

The self-reference handed to the step callback.

Returns

EntityBuilder<TResult>

A builder reading the recursive CTE from within its own step.

Type Parameters

TResult

The recursive CTE's projection shape.

Exceptions

ArgumentNullException

dataContext or reference is null.

InvalidOperationException

The reference is used outside its defining step (a captured or foreign reference).

From<TResult>(IDataContext, Cte<TResult>)

Starts a typed query from an ordinary CTE descriptor. The returned builder's primary source is the CTE name carrying the descriptor's projection shape, so the CTE is read directly (no derived SELECT wrapper) and every supported projection form resolves member access to the defining query's output columns. The declaration and its reachable dependencies are attached to the command, so a statement built over the source emits the required WITH. The descriptor is a typed projection source, not a mapped entity. Recursion is not part of this API; ordinary CTEs only.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, Cte<TResult> cte)

Parameters

dataContext IDataContext

The context to execute against.

cte Cte<TResult>

The descriptor returned by AsCte(string).

Returns

EntityBuilder<TResult>

A builder for composing the query over the CTE.

Type Parameters

TResult

The CTE's projection shape.

Exceptions

ArgumentNullException

dataContext or cte is null.

From<TResult>(IDataContext, EntityBuilder<TResult>)

Starts a new query builder that shares the source and definition of an existing builder.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, EntityBuilder<TResult> builder)

Parameters

dataContext IDataContext

The context to execute against.

builder EntityBuilder<TResult>

The builder to copy the query shape from.

Returns

EntityBuilder<TResult>

A new builder bound to dataContext.

Type Parameters

TResult

The projected element type.

From<TResult>(IDataContext, EntityBuilder<TResult>, Action<FromOptions>)

Starts a new query builder that shares the source and definition of an existing builder, with per-source options. The values set on options (currently the derived-table SubQueryHint) are copied into the returned builder; the options object is not retained.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, EntityBuilder<TResult> builder, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

builder EntityBuilder<TResult>

The builder to copy the query shape from.

options Action<FromOptions>

Configures the derived-table source, for example o => o.WithSubQueryHint("NestLoop(t1)").

Returns

EntityBuilder<TResult>

A new builder bound to dataContext.

Type Parameters

TResult

The projected element type.

From<TResult>(IDataContext, QueryCommand<TResult>)

Starts a query from an existing QueryCommand<TResult> and returns a fluent builder over its definition.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, QueryCommand<TResult> query)

Parameters

dataContext IDataContext

The context to execute against.

query QueryCommand<TResult>

The command whose definition drives the query.

Returns

EntityBuilder<TResult>

A builder for composing the query further.

Type Parameters

TResult

The projected element type.

Remarks

A single-column scalar source — including a set-operation command such as left.UnionAll(right) — materialises directly to List<T>. The read builds its own one-column shape and does not reuse the process-wide select-list cache entry of the result type, so a preceding scalar read that warmed that entry does not change the result. Before this behaviour, the warm path reused a cached object-materialisation list and threw QueryPreparationException ("Cannot get ctor from ..."), while the cold path succeeded. A derived source with more than one column still requires an explicit outer Select.

From<TResult>(IDataContext, QueryCommand<TResult>, Action<FromOptions>)

Starts a query from an existing QueryCommand<TResult> with per-source options. The values set on options (currently the derived-table SubQueryHint) are copied into the returned builder; the options object is not retained.

public static EntityBuilder<TResult> From<TResult>(this IDataContext dataContext, QueryCommand<TResult> query, Action<FromOptions> options)

Parameters

dataContext IDataContext

The context to execute against.

query QueryCommand<TResult>

The command whose definition drives the query.

options Action<FromOptions>

Configures the derived-table source, for example o => o.WithSubQueryHint("NestLoop(t1)").

Returns

EntityBuilder<TResult>

A builder for composing the query further.

Type Parameters

TResult

The projected element type.

From<TResult>(IDataContext, TempTableSource<TResult>)

Starts a query over a lazy temporary table created by AsTempTable<TResult>(QueryCommand<TResult>, CreateTableOptions?). Executing the returned query runs one batch on a single session — it drops and re-creates the temporary table from the source query, then reads it — so the table is always freshly materialised and the read never depends on connection pinning. Columns are read through TableAlias accessors (t.GetInt32("id")).

The form is available on PostgreSQL, SQLite, MySQL and MariaDB, the providers whose dialect can express a temporary CREATE TABLE ... AS SELECT. SQL Server, ClickHouse and the in-memory context reject it when the query renders.

public static EntityBuilder<TableAlias> From<TResult>(this IDataContext dataContext, TempTableSource<TResult> tempTable)

Parameters

dataContext IDataContext

The context to execute against.

tempTable TempTableSource<TResult>

The lazy source to materialise and read.

Returns

EntityBuilder<TableAlias>

A builder for composing the query over the temporary table.

Type Parameters

TResult

The source query's projected row type.

Exceptions

ArgumentNullException

dataContext or tempTable is null.

NotSupportedException

The context cannot execute a batch and therefore cannot materialise a temporary table (the in-memory provider).

From<T>(IDataContext, Action<EntityMetadataBuilder<T>>?)

Starts a query over the mapping of T and returns its fluent builder. The type's metadata is resolved lazily and cached per process; configEntity therefore runs only on the first call for T.

public static EntityBuilder<T> From<T>(this IDataContext dataContext, Action<EntityMetadataBuilder<T>>? configEntity = null)

Parameters

dataContext IDataContext
configEntity Action<EntityMetadataBuilder<T>>

Returns

EntityBuilder<T>

Type Parameters

T

From<T>(IDataContext, Action<FromOptions>, Action<EntityMetadataBuilder<T>>?)

Starts a query over the mapping of T with per-query source options. The values set on options (a TABLESAMPLE percentage, a ClickHouse SAMPLE ratio, or per-source table/index hints) are copied into the returned builder; the options object is not retained. The type's metadata is resolved exactly like From<T>(IDataContext, Action<EntityMetadataBuilder<T>>?).

public static EntityBuilder<T> From<T>(this IDataContext dataContext, Action<FromOptions> options, Action<EntityMetadataBuilder<T>>? configEntity = null)

Parameters

dataContext IDataContext

The context to execute against.

options Action<FromOptions>

Configures the primary source, for example o => o.TableSample(10) or o => o.WithTableHint("nolock").

configEntity Action<EntityMetadataBuilder<T>>

Optional mapping configuration, run only when the type is first mapped.

Returns

EntityBuilder<T>

A builder for composing the query.

Type Parameters

T

The mapped entity type.

From<T>(IDataContext, Expression<Func<EntityBuilder<T>>>)

Starts a query from a runtime table-valued-function descriptor supplied as an expression source, for example ctx.From(() => Db.MyTvf(42)). The lambda is required: a direct Db.MyTvf(42) call would pass an argument value and lose the expression, so only the lambda carries the call node whose arguments are rendered/parameterised like any other SQL expression.

The factory must return TvfEntityBuilder<T> for the same row type, and its metadata must not depend on the argument values. The argument expressions are kept untouched — a member of an outer row stays an outer-column reference, never an evaluated CLR value. Builder operations composed on the descriptor in the same lambda (Where, ordering and other builder-returning operations) are re-applied in their original order, so the source, its arguments and the composed operations all reach the query. A captured descriptor or any other shape without the original call expression is rejected with NotSupportedException.

public static EntityBuilder<T> From<T>(this IDataContext dataContext, Expression<Func<EntityBuilder<T>>> source)

Parameters

dataContext IDataContext

The context to execute against.

source Expression<Func<EntityBuilder<T>>>

The expression that calls the runtime factory, for example () => Db.MyTvf(42).

Returns

EntityBuilder<T>

A builder for composing the query over the function.

Type Parameters

T

The mapped row type the function returns, i.e. the result type of the composed chain.

Exceptions

ArgumentNullException

dataContext or source is null.

NotSupportedException

The expression is not a direct runtime-factory call or lost its argument provenance.

From<T>(IDataContext, Expression<Func<EntityBuilder<T>>>, Action<FromOptions>)

Starts a query from a runtime table-valued-function descriptor supplied as an expression source, with per-source options. See From<T>(IDataContext, Expression<Func<EntityBuilder<T>>>).

public static EntityBuilder<T> From<T>(this IDataContext dataContext, Expression<Func<EntityBuilder<T>>> source, Action<FromOptions> configure)

Parameters

dataContext IDataContext

The context to execute against.

source Expression<Func<EntityBuilder<T>>>

The expression that calls the runtime factory.

configure Action<FromOptions>

Configures the source placement, for example o => o.WithSubQueryHint("NestLoop(t1)").

Returns

EntityBuilder<T>

A builder for composing the query over the function.

Type Parameters

T

The mapped row type the function returns, i.e. the result type of the composed chain.

Exceptions

ArgumentNullException

dataContext, source or configure is null.

NotSupportedException

The expression is not a direct runtime-factory call or lost its argument provenance.

SingleAsync<TResult>(IDataContext, IPreparedQueryCommand<TResult>, params object[]?)

Asynchronously returns the only row of the query.

public static Task<TResult> SingleAsync<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<TResult>

The single materialized row.

Type Parameters

TResult

The projected element type.

Exceptions

InvalidOperationException

The query returns no rows or more than one row.

SingleOrDefaultAsync<TResult>(IDataContext, IPreparedQueryCommand<TResult>, params object[]?)

Asynchronously returns the only row of the query, or the default value of TResult when the query returns no rows.

public static Task<TResult?> SingleOrDefaultAsync<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<TResult>

The single materialized row, or default when there are none.

Type Parameters

TResult

The projected element type.

Exceptions

InvalidOperationException

The query returns more than one row.

ToListAsync<TResult>(IDataContext, IPreparedQueryCommand<TResult>, params object[]?)

Asynchronously executes the query and materializes every row into a new list.

public static Task<List<TResult>> ToListAsync<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand, params object[]? @params)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

params object[]

Positional parameter values, in the order the SQL references them.

Returns

Task<List<TResult>>

A list containing the materialized rows; empty when the query matches nothing.

Type Parameters

TResult

The projected element type.

ToList<TResult>(IDataContext, IPreparedQueryCommand<TResult>)

Synchronously executes the query and materializes every row into a new list, using no parameters.

public static List<TResult> ToList<TResult>(this IDataContext dataContext, IPreparedQueryCommand<TResult> preparedQueryCommand)

Parameters

dataContext IDataContext

The context to execute against.

preparedQueryCommand IPreparedQueryCommand<TResult>

The prepared query to execute.

Returns

List<TResult>

A list containing the materialized rows; empty when the query matches nothing.

Type Parameters

TResult

The projected element type.

ToSql<T1, T2>(JoinedEntityBuilder<T1, T2>)

Renders the multi-table DELETE the joined query would execute, without executing it. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2>(this JoinedEntityBuilder<T1, T2> query)

Parameters

query JoinedEntityBuilder<T1, T2>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3>(JoinedEntityBuilder<T1, T2, T3>)

Renders the multi-table DELETE a three-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3>(this JoinedEntityBuilder<T1, T2, T3> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3, T4>(JoinedEntityBuilder<T1, T2, T3, T4>)

Renders the multi-table DELETE a four-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3, T4>(this JoinedEntityBuilder<T1, T2, T3, T4> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3, T4, T5>(JoinedEntityBuilder<T1, T2, T3, T4, T5>)

Renders the multi-table DELETE a five-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3, T4, T5>(this JoinedEntityBuilder<T1, T2, T3, T4, T5> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3, T4, T5, T6>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>)

Renders the multi-table DELETE a six-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3, T4, T5, T6>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3, T4, T5, T6, T7>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>)

Renders the multi-table DELETE a seven-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3, T4, T5, T6, T7>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

ToSql<T1, T2, T3, T4, T5, T6, T7, T8>(JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>)

Renders the multi-table DELETE an eight-table join would execute. See Delete<T1, T2>(JoinedEntityBuilder<T1, T2>) for the full contract.

public static string ToSql<T1, T2, T3, T4, T5, T6, T7, T8>(this JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8> query)

Parameters

query JoinedEntityBuilder<T1, T2, T3, T4, T5, T6, T7, T8>

The joined query selecting the rows to delete.

Returns

string

The rendered SQL text.

Type Parameters

T1

The target entity type whose rows are deleted.

T2

The second joined entity type.

T3

The third joined entity type.

T4

The fourth joined entity type.

T5

The fifth joined entity type.

T6

The sixth joined entity type.

T7

The seventh joined entity type.

T8

The eighth joined entity type.

Exceptions

NotSupportedException

The provider has no native multi-table DELETE, or a join is not an INNER Join.

UpdateAsync<TEntity>(IDataContext, TEntity, CancellationToken)

Asynchronously updates the row identified by the declared key of entity in one command, using the mapping's [Key]/.Key().

public static Task<int> UpdateAsync<TEntity>(this IDataContext dataContext, TEntity entity, CancellationToken cancellationToken = default)

Parameters

dataContext IDataContext

The context to execute against.

entity TEntity

The entity whose key identifies the row and whose values are written.

cancellationToken CancellationToken

Cancels execution.

Returns

Task<int>

A task producing the number of updated rows (0 or 1).

Type Parameters

TEntity

The mapped entity type.

Exceptions

InvalidOperationException

The entity type declares no key.

NotSupportedException

The context does not support data modification (the in-memory provider), or the provider cannot express UPDATE (ClickHouse).

Update<TEntity>(IDataContext, TEntity)

Updates the row identified by the declared key of entity in one command (UPDATE ... SET ... WHERE <pk> = @p), writing every non-key, non-identity, non-computed column. Uses the mapping's [Key]/.Key().

public static int Update<TEntity>(this IDataContext dataContext, TEntity entity)

Parameters

dataContext IDataContext

The context to execute against.

entity TEntity

The entity whose key identifies the row and whose values are written.

Returns

int

The number of updated rows (0 or 1).

Type Parameters

TEntity

The mapped entity type.

Exceptions

InvalidOperationException

The entity type declares no key.

NotSupportedException

The context does not support data modification (the in-memory provider), or the provider cannot express UPDATE (ClickHouse).

With(IDataContext, string, QueryCommand)

Starts a CTE scope with a single non-recursive declaration.

public static CteQuery With(this IDataContext dataContext, string name, QueryCommand query)

Parameters

dataContext IDataContext
name string
query QueryCommand

Returns

CteQuery

WithRecursive(IDataContext, string, QueryCommand, int?)

Starts a CTE scope with a single recursive declaration. maxRecursion is rendered only by dialects that expose a depth option (SQL Server).

public static CteQuery WithRecursive(this IDataContext dataContext, string name, QueryCommand query, int? maxRecursion = null)

Parameters

dataContext IDataContext
name string
query QueryCommand
maxRecursion int?

Returns

CteQuery

With<TProjection, TResult>(IDataContext, string, DeleteJoinReturningBuilder<TProjection, TResult>)

Starts a CTE scope whose first declaration is a data-modifying common table expression whose body is a multi-table DELETE ... USING ... RETURNING. See With<TEntity, TResult>(IDataContext, string, DeleteReturningBuilder<TEntity, TResult>) for the full contract.

public static MutationCteQuery<TResult> With<TProjection, TResult>(this IDataContext dataContext, string name, DeleteJoinReturningBuilder<TProjection, TResult> delete)

Parameters

dataContext IDataContext

The context to execute against.

name string

The name the data-modifying CTE is declared under.

delete DeleteJoinReturningBuilder<TProjection, TResult>

The returning multi-table delete that forms the CTE body.

Returns

MutationCteQuery<TResult>

A scope that reads the mutation's returned rows and can declare more read CTEs.

Type Parameters

TProjection

The positional join projection (Projection<T1, ...>).

TResult

The row shape the CTE returns through RETURNING.

Exceptions

NotSupportedException

The active provider does not accept a data-modifying CTE body (only PostgreSQL does).

With<TEntity, TResult>(IDataContext, string, DeleteReturningBuilder<TEntity, TResult>)

Starts a CTE scope whose first declaration is a data-modifying common table expression whose body is a single-table DELETE ... RETURNING. See With<TEntity, TResult>(IDataContext, string, UpdateReturningBuilder<TEntity, TResult>) for the full contract.

public static MutationCteQuery<TResult> With<TEntity, TResult>(this IDataContext dataContext, string name, DeleteReturningBuilder<TEntity, TResult> delete)

Parameters

dataContext IDataContext

The context to execute against.

name string

The name the data-modifying CTE is declared under.

delete DeleteReturningBuilder<TEntity, TResult>

The returning delete that forms the CTE body.

Returns

MutationCteQuery<TResult>

A scope that reads the mutation's returned rows and can declare more read CTEs.

Type Parameters

TEntity

The mapped entity type whose rows are removed by the CTE body.

TResult

The row shape the CTE returns through RETURNING.

Exceptions

NotSupportedException

The active provider does not accept a data-modifying CTE body (only PostgreSQL does).

With<TEntity, TResult>(IDataContext, string, InsertReturningBuilder<TEntity, TResult>)

Starts a CTE scope whose first declaration is a data-modifying common table expression: the insert runs as the CTE body and its RETURNING rows are read through From(string). The scope is typed by TResult so the returned rows can be filtered, joined and projected.

Example: ctx.With("ins", ctx.CreateInsertBuilder<Order>().Values(o).Returning(x => new { x.Id })) .From("ins").Select(r => new { r.Id }).

public static MutationCteQuery<TResult> With<TEntity, TResult>(this IDataContext dataContext, string name, InsertReturningBuilder<TEntity, TResult> insert)

Parameters

dataContext IDataContext

The context to execute against.

name string

The name the data-modifying CTE is declared under.

insert InsertReturningBuilder<TEntity, TResult>

The returning insert that forms the CTE body.

Returns

MutationCteQuery<TResult>

A scope that reads the mutation's returned rows and can declare more read CTEs.

Type Parameters

TEntity

The mapped entity type inserted by the CTE body.

TResult

The row shape the CTE returns through RETURNING.

Exceptions

NotSupportedException

The active provider does not accept a data-modifying CTE body (only PostgreSQL does), or the context is the read-only in-memory provider.

With<TProjection, TResult>(IDataContext, string, UpdateJoinReturningBuilder<TProjection, TResult>)

Starts a CTE scope whose first declaration is a data-modifying common table expression whose body is a multi-table UPDATE ... FROM ... RETURNING. See With<TEntity, TResult>(IDataContext, string, UpdateReturningBuilder<TEntity, TResult>) for the full contract.

public static MutationCteQuery<TResult> With<TProjection, TResult>(this IDataContext dataContext, string name, UpdateJoinReturningBuilder<TProjection, TResult> update)

Parameters

dataContext IDataContext

The context to execute against.

name string

The name the data-modifying CTE is declared under.

update UpdateJoinReturningBuilder<TProjection, TResult>

The returning multi-table update that forms the CTE body.

Returns

MutationCteQuery<TResult>

A scope that reads the mutation's returned rows and can declare more read CTEs.

Type Parameters

TProjection

The positional join projection (Projection<T1, ...>).

TResult

The row shape the CTE returns through RETURNING.

Exceptions

NotSupportedException

The active provider does not accept a data-modifying CTE body (only PostgreSQL does).

With<TEntity, TResult>(IDataContext, string, UpdateReturningBuilder<TEntity, TResult>)

Starts a CTE scope whose first declaration is a data-modifying common table expression whose body is a single-table UPDATE ... RETURNING: the update runs as the CTE body and its returned rows are read through From(string). Only PostgreSQL accepts a data-modifying CTE body.

public static MutationCteQuery<TResult> With<TEntity, TResult>(this IDataContext dataContext, string name, UpdateReturningBuilder<TEntity, TResult> update)

Parameters

dataContext IDataContext

The context to execute against.

name string

The name the data-modifying CTE is declared under.

update UpdateReturningBuilder<TEntity, TResult>

The returning update that forms the CTE body.

Returns

MutationCteQuery<TResult>

A scope that reads the mutation's returned rows and can declare more read CTEs.

Type Parameters

TEntity

The mapped entity type whose rows are updated by the CTE body.

TResult

The row shape the CTE returns through RETURNING.

Exceptions

NotSupportedException

The active provider does not accept a data-modifying CTE body (only PostgreSQL does).