/// <summary> /// Process input parameters and get any dependencies ready. /// </summary> /// <returns>Returns a list of <see cref="IDisposable"/> elements that are needed to be held until statement execution is finished.</returns> private List <IDisposable> PrepareStatementDependencies() { // queries that provide DataTable as parameters are relying on the TVP-usage // we need to convert data tables into temp tables List <string> keysToRemove = new List <string>(); // need to keep trace of temp tables until statement is over List <IDisposable> tempTables = new List <IDisposable>(); foreach (var parameter in this.Parameters) { TableType tableType = parameter.Value as TableType; if (tableType != null) { TempTable tempTable = TempTable.CreateTemporaryTable(tableType.DataTable, this.Connection); tempTables.Add(tempTable); // can't remove key during enumeration, store them to remove later keysToRemove.Add(parameter.Key); // update command string to use actual temp table name, instead of parameter value this.CommandString = this.CommandString.Replace(parameter.Key, tempTable.TableName); } } foreach (string key in keysToRemove) { this.Parameters.Remove(key); } return(tempTables); }
/// <summary> /// Creates a temporary table using this context's database connection. /// </summary> /// <param name="table">The data table to be created as a temporary table in the database.</param> /// <returns>The temporary table created.</returns> public TempTable CreateTemporaryTable(DataTable table) { return(TempTable.CreateTemporaryTable(table, this.ConnectionManager.Connection)); }