Table of Contents

Class TempTable<T>

Namespace
LinqToDB
Assembly
linq2db.dll

Temporary table. Temporary table is a table, created when you create instance of this class and deleted when you dispose it. It uses regular tables even if underlying database supports temporary tables concept.

public class TempTable<T> : ITable<T>, IExpressionQuery<T>, IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IOrderedQueryable, IQueryable, IEnumerable, IQueryProviderAsync, IQueryProvider, IExpressionQuery, ITableMutable<T>, IDisposable, IAsyncDisposable where T : notnull

Type Parameters

T

Table record mapping class.

Inheritance
TempTable<T>
Implements
Extension Methods

Constructors

TempTable(IDataContext, IEnumerable<T>, BulkCopyOptions?, string?, string?, string?, string?, TableOptions)

Creates new temporary table and populate it using BulkCopy.

public TempTable(IDataContext db, IEnumerable<T> items, BulkCopyOptions? options = null, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet)

Parameters

db IDataContext

Database connection instance.

items IEnumerable<T>

Initial records to insert into created table.

options BulkCopyOptions

Optional BulkCopy options.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

TempTable(IDataContext, IQueryable<T>, string?, string?, string?, Action<ITable<T>>?, string?, TableOptions)

Creates new temporary table and populate it using data from provided query.

public TempTable(IDataContext db, IQueryable<T> items, string? tableName = null, string? databaseName = null, string? schemaName = null, Action<ITable<T>>? action = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet)

Parameters

db IDataContext

Database connection instance.

items IQueryable<T>

Query to get records to populate created table with initial data.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

action Action<ITable<T>>

Optional action that will be executed after table creation but before it populated with data from items.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

TempTable(IDataContext, string?, IEnumerable<T>, BulkCopyOptions?, string?, string?, string?, TableOptions)

Creates new temporary table and populate it using BulkCopy.

public TempTable(IDataContext db, string? tableName, IEnumerable<T> items, BulkCopyOptions? options = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

items IEnumerable<T>

Initial records to insert into created table.

options BulkCopyOptions

Optional BulkCopy options.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

TempTable(IDataContext, string?, IQueryable<T>, string?, string?, Action<ITable<T>>?, string?, TableOptions)

Creates new temporary table and populate it using data from provided query.

public TempTable(IDataContext db, string? tableName, IQueryable<T> items, string? databaseName = null, string? schemaName = null, Action<ITable<T>>? action = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

items IQueryable<T>

Query to get records to populate created table with initial data.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

action Action<ITable<T>>

Optional action that will be executed after table creation but before it populated with data from items.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

TempTable(IDataContext, string?, string?, string?, string?, TableOptions)

Creates new temporary table.

public TempTable(IDataContext db, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

TempTable(ITable<T>, EntityDescriptor?)

Configures a temporary table that will be dropped when this instance is disposed

protected TempTable(ITable<T> table, EntityDescriptor? tableDescriptor)

Parameters

table ITable<T>

Table instance.

tableDescriptor EntityDescriptor

Temporary table entity descriptor.

Fields

TotalCopied

Gets total number of records, inserted into table using BulkCopy.

public long TotalCopied

Field Value

long

Properties

DataContext

Gets data connection, associated with current table.

public IDataContext DataContext { get; }

Property Value

IDataContext

DatabaseName

public string? DatabaseName { get; }

Property Value

string

SchemaName

public string? SchemaName { get; }

Property Value

string

ServerName

public string? ServerName { get; }

Property Value

string

TableID

public string? TableID { get; }

Property Value

string

TableName

public string TableName { get; }

Property Value

string

TableOptions

public TableOptions TableOptions { get; }

Property Value

TableOptions

Methods

Copy(IEnumerable<T>, BulkCopyOptions?)

Insert new records into table using BulkCopy.

public long Copy(IEnumerable<T> items, BulkCopyOptions? options = null)

Parameters

items IEnumerable<T>

Records to insert into table.

options BulkCopyOptions

Optional BulkCopy options.

Returns

long

Number of records, inserted into table.

CopyAsync(IEnumerable<T>, BulkCopyOptions?, CancellationToken)

Insert new records into table using BulkCopy.

public Task<long> CopyAsync(IEnumerable<T> items, BulkCopyOptions? options = null, CancellationToken cancellationToken = default)

Parameters

items IEnumerable<T>

Records to insert into table.

options BulkCopyOptions

Optional BulkCopy options.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<long>

Number of records, inserted into table.

CreateAsync(IDataContext, IEnumerable<T>, BulkCopyOptions?, string?, string?, string?, string?, TableOptions, CancellationToken)

Creates new temporary table and populate it using BulkCopy.

public static Task<TempTable<T>> CreateAsync(IDataContext db, IEnumerable<T> items, BulkCopyOptions? options = null, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default)

Parameters

db IDataContext

Database connection instance.

items IEnumerable<T>

Initial records to insert into created table.

options BulkCopyOptions

Optional BulkCopy options.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<TempTable<T>>

CreateAsync(IDataContext, IQueryable<T>, string?, string?, string?, Func<ITable<T>, Task>?, string?, TableOptions, CancellationToken)

Creates new temporary table and populate it using data from provided query.

public static Task<TempTable<T>> CreateAsync(IDataContext db, IQueryable<T> items, string? tableName = null, string? databaseName = null, string? schemaName = null, Func<ITable<T>, Task>? action = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default)

Parameters

db IDataContext

Database connection instance.

items IQueryable<T>

Query to get records to populate created table with initial data.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

action Func<ITable<T>, Task>

Optional asynchronous action that will be executed after table creation but before it populated with data from items.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<TempTable<T>>

CreateAsync(IDataContext, string?, IEnumerable<T>, BulkCopyOptions?, string?, string?, string?, TableOptions, CancellationToken)

Creates new temporary table and populate it using BulkCopy.

public static Task<TempTable<T>> CreateAsync(IDataContext db, string? tableName, IEnumerable<T> items, BulkCopyOptions? options = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

items IEnumerable<T>

Initial records to insert into created table.

options BulkCopyOptions

Optional BulkCopy options.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<TempTable<T>>

CreateAsync(IDataContext, string?, IQueryable<T>, string?, string?, Func<ITable<T>, Task>?, string?, TableOptions, CancellationToken)

Creates new temporary table and populate it using data from provided query.

public static Task<TempTable<T>> CreateAsync(IDataContext db, string? tableName, IQueryable<T> items, string? databaseName = null, string? schemaName = null, Func<ITable<T>, Task>? action = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

items IQueryable<T>

Query to get records to populate created table with initial data.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

action Func<ITable<T>, Task>

Optional asynchronous action that will be executed after table creation but before it populated with data from items.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<TempTable<T>>

CreateAsync(IDataContext, string?, string?, string?, string?, TableOptions, CancellationToken)

Creates new temporary table.

public static Task<TempTable<T>> CreateAsync(IDataContext db, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default)

Parameters

db IDataContext

Database connection instance.

tableName string

Optional name of temporary table. If not specified, value from mapping will be used.

databaseName string

Optional name of table's database. If not specified, value from mapping will be used.

schemaName string

Optional name of table schema/owner. If not specified, value from mapping will be used.

serverName string

Optional name of linked server. If not specified, value from mapping will be used.

tableOptions TableOptions

Optional Table options. If not specified, value from mapping will be used.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<TempTable<T>>

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public virtual Task DisposeAsync()

Returns

Task

Insert(IQueryable<T>)

Insert data into table using records, returned by provided query.

public long Insert(IQueryable<T> items)

Parameters

items IQueryable<T>

Query with records to insert into temporary table.

Returns

long

Number of records, inserted into table.

InsertAsync(IQueryable<T>, CancellationToken)

Insert data into table using records, returned by provided query.

public Task<long> InsertAsync(IQueryable<T> items, CancellationToken cancellationToken = default)

Parameters

items IQueryable<T>

Query with records to insert into temporary table.

cancellationToken CancellationToken

Asynchronous operation cancellation token.

Returns

Task<long>

Number of records, inserted into table.