Beispiel #1
0
        private SqlBulkCopy CreateSqlBulkCopy(DbContext context, SqlConnection connection, DataTable table, Type type, int timeout = 0)
        {
            var bulkCopy = new SqlBulkCopy(connection)
            {
                DestinationTableName = _tableHandler.GetTableName(context, type)
            };

            //Map columns to their names (otherwise it missmatches them for some reason)
            foreach (DataColumn prepped in table.Columns)
            {
                bulkCopy.ColumnMappings.Add(prepped.ColumnName, prepped.ColumnName);
            }

            bulkCopy.BulkCopyTimeout = timeout;
            return(bulkCopy);
        }