mgravell / fast-member

Automatically exported from code.google.com/p/fast-member
Apache License 2.0
1.02k stars 137 forks source link

BulkCopy works in a very weird way #47

Open gilmishal opened 6 years ago

gilmishal commented 6 years ago

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