Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Raxidi opened this issue Mar 17, 2023 · 2 comments
Labels

Comments

@Raxidi
Copy link

Raxidi commented Mar 17, 2023

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
Copy link
Author

Raxidi commented Mar 17, 2023

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

@Raxidi
Copy link
Author

Raxidi commented Oct 30, 2024

@schotime : Any timelines for v6? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants