schotime / NPoco

Simple microORM that maps the results of a query onto a POCO object. Project based on Schotime's branch of PetaPoco
Apache License 2.0
848 stars 302 forks source link

InsertBulkAsync<T> fails with error: Cannot change DataType of a column once it has data. #684

Open Raxidi opened 1 year ago

Raxidi commented 1 year ago

Firstly this is a great library and thanks a ton @schotime !!

I am facing with the issue with InsertBulkAsync where my poco class has nullable properties. I'm getting "Cannot change DataType of a column once it has data. : at System.Data.DataColumn.set_DataType(Type value)....." when InsertBulkAsync is called.

NPoco.SqlServer v.5.7.0

Here is the code snippet:

using(var transaction = db.GetTransaction())
{
    await db.InsertBulkAsync<MyClass>(listOfMyclassObjects);
}

and here is the poco class definition.

[TableName("MyTableName")]
[PrimaryKey("ID", AutoIncrement = true)]
public class MyClass
{
    [Column("ID")]
    public int ID { get; set; }

    [Column("TextID")]
    public string TextID { get; set; }

    [Column("DocID")]
    public string DocID { get; set; }

    [Column("DocumentName")]
    public string DocumentName { get; set; }

    [Column("PageNum")]
    public int? PageNum { get; set; }

    [Column("Label")]
    public string Label { get; set; }

    [Column("Value")]
    public string Value { get; set; }

    [Column("LabelID")]
    public int? LabelID { get; set; }

    [Column("SplitValue1")]
    public string SplitValue1 { get; set; }

    [Column("SplitValue2")]
    public string SplitValue2 { get; set; }

    [Column("SplitValue3")]
    public string SplitValue3 { get; set; }

    [Column("SplitValue4")]
    public string SplitValue4 { get; set; }

    [Column("SplitValue5")]
    public string SplitValue5 { get; set; }

    [Column("SplitValue6")]
    public string SplitValue6 { get; set; }

    [Column("FromOldBatch")]
    public bool? FromOldBatch { get; set; }
}

Am I doing anything wrong? Thanks a lot.

Raxidi commented 1 year ago

Update: Removing the transaction doesn't make any difference.

Raxidi commented 1 week ago

@schotime : Any timelines for v6? Thanks.