SqlBulkInserter makes 2 bad assumptions about the records it gets in a bulk insert:
All records contain the same columns (or at least that the first record has all of the columns since only the first is used to generate the data table and all 'optional' columns are at the end)
Calling record.Values.ToArray() will yield the same column ordering on all records.
In the example above, when SqlBulkInserter tries to add the row for r2 with dataTable.Rows.Add(record.Values.ToArray()) it will generate an exception stating "input array is longer than the number of columns" because the table only has 2 columns.
If, however, you passed the records in the other order (db.People.Insert(new [] {r2, r1})), It wouldn't error, but r1's data wouldn't be correctly inserted: "Dole" would be in the MiddleInitial column instead of Last Name because the order of adding those values to the record effects the order of the values in the ToArray call.
SqlBulkInserter makes 2 bad assumptions about the records it gets in a bulk insert:
record.Values.ToArray()
will yield the same column ordering on all records.In the example above, when SqlBulkInserter tries to add the row for r2 with
dataTable.Rows.Add(record.Values.ToArray())
it will generate an exception stating "input array is longer than the number of columns" because the table only has 2 columns.If, however, you passed the records in the other order (
db.People.Insert(new [] {r2, r1})
), It wouldn't error, but r1's data wouldn't be correctly inserted: "Dole" would be in the MiddleInitial column instead of Last Name because the order of adding those values to the record effects the order of the values in the ToArray call.