public void BulkInsertWP(WPList wpList) { try { string bulkInsertString = BuildBulkInsertString(wpList); ((DBWPPreselection)GetEntity()).BulkInsert(bulkInsertString); } catch (Exception ex) { throw new IndException(ex); } }
/// <summary> /// Creates the bulk insert string /// </summary> /// <param name="wpList">list containing IntercoLogicalKey objects</param> /// <returns>the bulk insert string</returns> private string BuildBulkInsertString(WPList wpList) { StringBuilder bulkInsertString = new StringBuilder(); bulkInsertString.Append("IF object_id(N'tempdb.dbo.#BUDGET_PRESELECTION_TEMP') IS NULL CREATE TABLE #BUDGET_PRESELECTION_TEMP (IdProject INT, IdPhase INT, IdWP INT)\r\n"); bulkInsertString.Append("DELETE FROM #BUDGET_PRESELECTION_TEMP\r\n"); //Start of transaction bulkInsertString.Append("BEGIN TRANSACTION\r\n"); //Insert template string insertTemplate = "INSERT INTO #BUDGET_PRESELECTION_TEMP VALUES({0}, {1}, {2})\r\n"; //Insert values foreach (IntercoLogicalKey key in wpList) { string currentInsert = string.Format(insertTemplate, key.IdProject, key.IdPhase, key.IdWP); bulkInsertString.Append(currentInsert); } //End transaction bulkInsertString.Append("COMMIT TRANSACTION"); return(bulkInsertString.ToString()); }