igor-tkachev / bltoolkit

Business Logic Toolkit for .NET
MIT License
297 stars 113 forks source link

Fix 'InsertBatch' #311

Closed Firebie closed 10 years ago

Firebie commented 10 years ago

Problem: 'BulkCopyReader.GetValue' relies on _members index, not on 'memberMapper.Ordinal', and here, in example, field 'id' is not inside _members, so, we get out of index exception.

To reproduce problem:

create table test
(
  id int not null identity(1, 1),
  data nvarchar(50),
  constraint pk_test primary key(id)
)
  public class Test
  {
    [PrimaryKey, NonUpdatable, Identity]
    public int    id;
    public string data;
 }

using (var db = new DbManager())
{
    var testlist = new List<Test>();

    db.BeginTransaction();

    testlist.Add(new Test { data = "1" });
    testlist.Add(new Test { data = "2" });

    db.InsertBatch(testlist);

    db.CommitTransaction();
}