fast-member icon indicating copy to clipboard operation
fast-member copied to clipboard

BulkCopy works in a very weird way

Open gilmishal opened this issue 7 years ago • 0 comments

I have the following test code targeting net47

static void Main(string[] args)
{
       var connection = new SqlConnection(_connectionString);
       connection.Open();
       var collection = new List<AnyType>();

       for (int i = 0; i < 2000; i++)
       {
           collection.Add(new AnyType { Data = "asdfasr", somethingElse = "casdf" });
       }
       using (var copy = new SqlBulkCopy(connection))
       using (var reader = ObjectReader.Create(collection, "Data", "somethingElse"))
       {
           copy.DestinationTableName = "anyTable";
           copy.WriteToServer(reader);
       }
           connection.Close();
}

class AnyType
{
       public string somethingElse { get; set; }
       public string Data { get; set; }
}

for some reason the resulting copy inserts the value of somethingElse into Data and inserts nulls in somethingElse

gilmishal avatar Dec 17 '17 15:12 gilmishal