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
-
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
db
IDataContextDatabase connection instance.
items
IEnumerable<T>Initial records to insert into created table.
options
BulkCopyOptionsOptional BulkCopy options.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional 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
IDataContextDatabase connection instance.
items
IQueryable<T>Query to get records to populate created table with initial data.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional 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
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional 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
IDataContextDatabase connection instance.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
items
IEnumerable<T>Initial records to insert into created table.
options
BulkCopyOptionsOptional BulkCopy options.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional 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
IDataContextDatabase connection instance.
tableName
stringOptional 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
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional 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
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional 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
IDataContextDatabase connection instance.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional 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
EntityDescriptorTemporary 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
items
IEnumerable<T>Records to insert into table.
options
BulkCopyOptionsOptional 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
BulkCopyOptionsOptional BulkCopy options.
cancellationToken
CancellationTokenAsynchronous 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
db
IDataContextDatabase connection instance.
items
IEnumerable<T>Initial records to insert into created table.
options
BulkCopyOptionsOptional BulkCopy options.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationToken
CancellationTokenAsynchronous 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
db
IDataContextDatabase connection instance.
items
IQueryable<T>Query to get records to populate created table with initial data.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional 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
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationToken
CancellationTokenAsynchronous 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
db
IDataContextDatabase connection instance.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
items
IEnumerable<T>Initial records to insert into created table.
options
BulkCopyOptionsOptional BulkCopy options.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationToken
CancellationTokenAsynchronous 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
db
IDataContextDatabase connection instance.
tableName
stringOptional 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
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional 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
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationToken
CancellationTokenAsynchronous 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
db
IDataContextDatabase connection instance.
tableName
stringOptional name of temporary table. If not specified, value from mapping will be used.
databaseName
stringOptional name of table's database. If not specified, value from mapping will be used.
schemaName
stringOptional name of table schema/owner. If not specified, value from mapping will be used.
serverName
stringOptional name of linked server. If not specified, value from mapping will be used.
tableOptions
TableOptionsOptional Table options. If not specified, value from mapping will be used.
cancellationToken
CancellationTokenAsynchronous 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
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
CancellationTokenAsynchronous operation cancellation token.