Class TempTableExtensions
Materialises a query into a table: CREATE TABLE ... AS SELECT (PostgreSQL, SQLite, MySQL, MariaDB),
SELECT ... INTO (SQL Server) or CREATE TABLE ... ENGINE = MergeTree ... AS SELECT
(ClickHouse). The row shape is taken from the query's projection; the created table is addressed later
with From(IDataContext, string). Unlike a common table expression,
which is reusable only within one statement, the materialised table is reusable across subsequent
queries on the same connection.
The temporary form (ToTempTable) is session-scoped: create and read it on one context (one
connection). It is available on PostgreSQL, SQLite, MySQL and MariaDB only — SQL Server has no
CREATE TEMPORARY TABLE ... AS SELECT (a session-scoped table is ToTable("#name")) and
ClickHouse cannot express a temporary AS SELECT. The terminal issues exactly one command and
returns no row count; the in-memory context rejects it with NotSupportedException.
Every terminal is offered both on a query builder (before a projection) and on a built
QueryCommand<TResult> (after Select), so a projection can be materialised too.
public static class TempTableExtensions
- Inheritance
-
TempTableExtensions
- Inherited Members
Methods
AsTempTable<TResult>(EntityBuilder<TResult>, CreateTableOptions?)
Wraps a builder's query (every column of the source) in a lazy temporary-table source. Nothing is executed until the source is read. See AsTempTable<TResult>(QueryCommand<TResult>, CreateTableOptions?) for the contract.
public static TempTableSource<TResult> AsTempTable<TResult>(this EntityBuilder<TResult> builder, CreateTableOptions? options = null)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
optionsCreateTableOptionsOptional materialisation options.
Returns
- TempTableSource<TResult>
A source to read back with
Fromon the same context.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
builderis null.
AsTempTable<TResult>(EntityBuilder<TResult>, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Wraps a builder's query (every column of the source) in a lazy temporary-table source, configuring the materialisation options fluently. Nothing is executed until the source is read.
public static TempTableSource<TResult> AsTempTable<TResult>(this EntityBuilder<TResult> builder, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the materialisation options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- TempTableSource<TResult>
A source to read back with
Fromon the same context.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
builderorconfigureis null.
AsTempTable<TResult>(QueryCommand<TResult>, CreateTableOptions?)
Wraps a built query in a lazy temporary-table source. Nothing is executed: the table is materialised (and read) only when a query reads the source through From<TResult>(IDataContext, TempTableSource<TResult>).
public static TempTableSource<TResult> AsTempTable<TResult>(this QueryCommand<TResult> query, CreateTableOptions? options = null)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
optionsCreateTableOptionsOptional materialisation options.
Returns
- TempTableSource<TResult>
A source to read back with
Fromon the same context.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
queryis null.
AsTempTable<TResult>(QueryCommand<TResult>, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Wraps a built query in a lazy temporary-table source, configuring the materialisation options fluently. Nothing is executed until the source is read.
public static TempTableSource<TResult> AsTempTable<TResult>(this QueryCommand<TResult> query, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the materialisation options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- TempTableSource<TResult>
A source to read back with
Fromon the same context.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
queryorconfigureis null.
ToBatchSql<TResult>(QueryCommand<TResult>)
Renders the batch a query reading a lazy temporary table would execute — the table's
DROP TABLE IF EXISTS and CREATE TEMPORARY TABLE ... AS SELECT followed by the read
query — without executing it.
public static string ToBatchSql<TResult>(this QueryCommand<TResult> query)
Parameters
queryQueryCommand<TResult>The query reading a source created with AsTempTable<TResult>(QueryCommand<TResult>, CreateTableOptions?).
Returns
- string
The rendered batch SQL.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
queryis null.- InvalidOperationException
The query does not read a temporary table.
- NotSupportedException
The context or provider cannot execute a batch or express a temporary materialisation.
ToTableAsync<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?, CancellationToken)
Asynchronously materialises a builder's query into a persistent table.
public static Task ToTableAsync<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null, CancellationToken cancellationToken = default)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options; OnCommit is invalid here.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableAsync<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>, CancellationToken)
Asynchronously materialises a builder's query into the persistent table, configuring the options fluently.
public static Task ToTableAsync<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure, CancellationToken cancellationToken = default)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored. OnCommit is invalid here.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableAsync<TResult>(QueryCommand<TResult>, string, CreateTableOptions?, CancellationToken)
Asynchronously materialises a built query into a persistent table.
public static Task ToTableAsync<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null, CancellationToken cancellationToken = default)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options; OnCommit is invalid here.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableAsync<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>, CancellationToken)
Asynchronously materialises a built query into the persistent table, configuring the options fluently.
public static Task ToTableAsync<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure, CancellationToken cancellationToken = default)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored. OnCommit is invalid here.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableSql<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?)
Renders the persistent-table statement a builder's query would execute, without executing it.
public static string ToTableSql<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableSql<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Renders the persistent-table statement a builder's query would execute, configuring the options fluently and without executing it.
public static string ToTableSql<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableSql<TResult>(QueryCommand<TResult>, string, CreateTableOptions?)
Renders the persistent-table statement a built query would execute, without executing it.
public static string ToTableSql<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTableSql<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Renders the persistent-table statement a built query would execute, configuring the options fluently and without executing it.
public static string ToTableSql<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTable<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?)
Materialises a builder's query into the persistent table name.
public static void ToTable<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
optionsCreateTableOptionsOptional statement options; OnCommit is invalid here.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTable<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Materialises a builder's query into the persistent table name, configuring the options fluently.
public static void ToTable<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored. OnCommit is invalid here.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTable<TResult>(QueryCommand<TResult>, string, CreateTableOptions?)
Materialises a built query into the persistent table name.
public static void ToTable<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
optionsCreateTableOptionsOptional statement options; OnCommit is invalid here.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTable<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Materialises a built query into the persistent table name, configuring the options fluently.
public static void ToTable<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored. OnCommit is invalid here.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableAsync<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?, CancellationToken)
Asynchronously materialises a builder's query into a temporary table.
public static Task ToTempTableAsync<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null, CancellationToken cancellationToken = default)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableAsync<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>, CancellationToken)
Asynchronously materialises a builder's query into the temporary table, configuring the options fluently.
public static Task ToTempTableAsync<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure, CancellationToken cancellationToken = default)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableAsync<TResult>(QueryCommand<TResult>, string, CreateTableOptions?, CancellationToken)
Asynchronously materialises a built query into a temporary table.
public static Task ToTempTableAsync<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null, CancellationToken cancellationToken = default)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableAsync<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>, CancellationToken)
Asynchronously materialises a built query into the temporary table, configuring the options fluently.
public static Task ToTempTableAsync<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure, CancellationToken cancellationToken = default)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
cancellationTokenCancellationTokenCancels execution.
Returns
- Task
A task that completes when the table has been created.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableSql<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?)
Renders the temporary-table statement a builder's query would execute, without executing it.
public static string ToTempTableSql<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableSql<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Renders the temporary-table statement a builder's query would execute, configuring the options fluently and without executing it.
public static string ToTempTableSql<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableSql<TResult>(QueryCommand<TResult>, string, CreateTableOptions?)
Renders the temporary-table statement a built query would execute, without executing it.
public static string ToTempTableSql<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
optionsCreateTableOptionsOptional statement options.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTableSql<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Renders the temporary-table statement a built query would execute, configuring the options fluently and without executing it.
public static string ToTempTableSql<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Returns
- string
The rendered SQL text.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTable<TResult>(EntityBuilder<TResult>, string, CreateTableOptions?)
Materialises a builder's query into the temporary table name.
public static void ToTempTable<TResult>(this EntityBuilder<TResult> builder, string name, CreateTableOptions? options = null)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
optionsCreateTableOptionsOptional statement options.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTable<TResult>(EntityBuilder<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Materialises a builder's query into the temporary table name, configuring the options fluently.
public static void ToTempTable<TResult>(this EntityBuilder<TResult> builder, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
builderEntityBuilder<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTable<TResult>(QueryCommand<TResult>, string, CreateTableOptions?)
Materialises a built query into the temporary table name.
public static void ToTempTable<TResult>(this QueryCommand<TResult> query, string name, CreateTableOptions? options = null)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
optionsCreateTableOptionsOptional statement options.
Type Parameters
TResultThe query's projected row type.
Exceptions
- NotSupportedException
The context or provider cannot express the statement or one of the requested options.
ToTempTable<TResult>(QueryCommand<TResult>, string, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder>)
Materialises a built query into the temporary table name, configuring the options fluently.
public static void ToTempTable<TResult>(this QueryCommand<TResult> query, string name, Func<CreateTableOptionsBuilder, CreateTableOptionsBuilder> configure)
Parameters
queryQueryCommand<TResult>The query whose rows fill the table.
namestringThe raw (unquoted) target table name; the naming convention is not applied.
configureFunc<CreateTableOptionsBuilder, CreateTableOptionsBuilder>Configures the statement options through CreateTableOptionsBuilder; its return value is ignored.
Type Parameters
TResultThe query's projected row type.
Exceptions
- ArgumentNullException
configureis null.- NotSupportedException
The context or provider cannot express the statement or one of the requested options.