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
TTable record mapping class.
- Inheritance
-
TempTable<T>
- Implements
-
ITable<T>IQueryable<T>IEnumerable<T>
- 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
dbIDataContextDatabase connection instance.
itemsIEnumerable<T>Initial records to insert into created table.
optionsBulkCopyOptionsOptional BulkCopy options.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional 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
dbIDataContextDatabase connection instance.
itemsIQueryable<T>Query to get records to populate created table with initial data.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
actionAction<ITable<T>>Optional action that will be executed after table creation but before it populated with data from
items.serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional 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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
itemsIEnumerable<T>Initial records to insert into created table.
optionsBulkCopyOptionsOptional BulkCopy options.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional 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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
itemsIQueryable<T>Query to get records to populate created table with initial data.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
actionAction<ITable<T>>Optional action that will be executed after table creation but before it populated with data from
items.serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional 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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional 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
tableITable<T>Table instance.
tableDescriptorEntityDescriptorTemporary table entity descriptor.
Fields
TotalCopied
Gets total number of records, inserted into table using BulkCopy.
public long TotalCopied
Field Value
Properties
DataContext
Gets data connection, associated with current table.
public IDataContext DataContext { get; }
Property Value
DatabaseName
public string? DatabaseName { get; }
Property Value
SchemaName
public string? SchemaName { get; }
Property Value
ServerName
public string? ServerName { get; }
Property Value
TableID
public string? TableID { get; }
Property Value
TableName
public string TableName { get; }
Property Value
TableOptions
public TableOptions TableOptions { get; }
Property Value
Methods
Copy(IEnumerable<T>, BulkCopyOptions?)
Insert new records into table using BulkCopy.
public long Copy(IEnumerable<T> items, BulkCopyOptions? options = null)
Parameters
itemsIEnumerable<T>Records to insert into table.
optionsBulkCopyOptionsOptional 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
itemsIEnumerable<T>Records to insert into table.
optionsBulkCopyOptionsOptional BulkCopy options.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
dbIDataContextDatabase connection instance.
itemsIEnumerable<T>Initial records to insert into created table.
optionsBulkCopyOptionsOptional BulkCopy options.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
dbIDataContextDatabase connection instance.
itemsIQueryable<T>Query to get records to populate created table with initial data.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
actionFunc<ITable<T>, Task>Optional asynchronous action that will be executed after table creation but before it populated with data from
items.serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
itemsIEnumerable<T>Initial records to insert into created table.
optionsBulkCopyOptionsOptional BulkCopy options.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
itemsIQueryable<T>Query to get records to populate created table with initial data.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
actionFunc<ITable<T>, Task>Optional asynchronous action that will be executed after table creation but before it populated with data from
items.serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
dbIDataContextDatabase connection instance.
tableNamestringOptional name of temporary table. If not specified, value from mapping will be used.
databaseNamestringOptional name of table's database. If not specified, value from mapping will be used.
schemaNamestringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
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
Insert(IQueryable<T>)
Insert data into table using records, returned by provided query.
public long Insert(IQueryable<T> items)
Parameters
itemsIQueryable<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
itemsIQueryable<T>Query with records to insert into temporary table.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.