private void SetupMappings(SqlBulkCopy bcp)
        {
            var properties = GetterDelegateCache <TInput> .ReadablePropertyNames.ToArray();

            var conn = bcp.GetConnection();

            var destination = bcp.DestinationTableName;

            var destinationParts = new List <string>(SqlIdentifier.Parse(destination));

            while (destinationParts.Count < 3)
            {
                destinationParts.Insert(0, null);
            }

            var schemaTable = conn.GetSchema("Columns", destinationParts.ToArray());

            var columns = schemaTable.Rows.Cast <DataRow>()
                          .Select(r => (string)r[3])
                          .ToArray();

            foreach (var map in properties.Intersect(columns, StringComparer.InvariantCultureIgnoreCase))
            {
                bcp.ColumnMappings.Add(new SqlBulkCopyColumnMapping(map, map));
            }
        }
Пример #2
0
 private UpdateOperation(SqlBulkCopy bulkCopy, string[] keyColumns, string[] dataColumns)
 {
     _connection           = bulkCopy.GetConnection();
     _bulkCopy             = bulkCopy;
     _destinationTableName = bulkCopy.DestinationTableName;
     _tempTableName        = "tmpUpdate" + Guid.NewGuid().ToString().Replace("-", string.Empty);
     _keyColumnNames       = keyColumns;
     _dataColumnNames      = dataColumns;
     if (!_keyColumnNames.Any())
     {
         throw new ApplicationException("No key columns provided.");
     }
 }
Пример #3
0
        public void GetConnection()
        {
            // Examples
            using (var conn = new SqlConnection(My.Config.ConnectionString.UnitTest.ConnectionString))
            {
                using (var @this = new SqlBulkCopy(conn))
                {
                    SqlConnection result = @this.GetConnection();

                    // Unit Test
                    Assert.AreEqual(conn, result);
                }
            }
        }