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

Null reference exception on BulkInsert #58

Closed
jspinella opened this issue Jan 16, 2020 · 9 comments
Closed

Null reference exception on BulkInsert #58

jspinella opened this issue Jan 16, 2020 · 9 comments
Assignees

Comments

@jspinella
Copy link

Essentially I am experiencing #28 using MySql.Data 8.0.19 (also tried 6.10.9) and Z.Dapper.Plus 3.0.0 (so as to not get the trial expired exception in Jan 2020).

I know this is usually a problem with the user code and not an issue with Dapper itself, but it seems to have started happening after upgrading to the latest version of Dapper.Plus (v3.0.0).

Here's the stack trace excluding the call from my repo method to BulkInsert():
at Z.Dapper.Plus.DapperPlusAction.Execute() at Z.Dapper.Plus.DapperPlusActionSet1.DapperPlusActionSetBuilder(DapperPlusContext context, IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, IEnumerable1 items, Func2[] selectors)
at Z.Dapper.Plus.DapperPlusActionSet1..ctor(DapperPlusContext context, IDbConnection connection, String mapperKey, DapperPlusActionKind actionKind, IEnumerable1 items, Func2[] selectors) at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, String mapperKey, IEnumerable1 items, Func2[] selectors) at Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, IEnumerable1 items, Func2[] selectors)

I get this error when attempting to bulk insert into a MySql table. I have confirmed that the column names are identical (down to the casing) between the MySql table and the C# poco. Currently I am getting this exception when attempting to BulkInsert on a single record from the large number of records I was INSERTing before, just to rule out potential nulls in the records. Standard Dapper methods that SELECT from MySql tables are executing without issue leading up to this exception (for what that's worth).

@JonathanMagnan JonathanMagnan self-assigned this Jan 16, 2020
@JonathanMagnan
Copy link
Member

Hello @jspinella ,

Thank you for reporting,

I will ask my developer to look at it to see if he has enough information to reproduce the issue.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @jspinella ,

Do you think you could provide us more info such as a runnable unit test project with this error?

My developer looked at it but could not reproduce a similar error with the current info you provided.

@jspinella
Copy link
Author

jspinella commented Jan 17, 2020

Sure thing:

https://github.com/jspinella/DapperPlusTest

This is a much simpler example of the code I am working with in production, but the issue is the same.

I figure since you guys haven't been able to reproduce, it's probably an issue with the MySql.Data NuGet package or how Dapper.Plus interfaces with MySql.Data. Of course I could be missing something obvious, too.

@yfunck-vix
Copy link

Hello,

I can confirm that the problem is neither with your code, nor with the SGBD you use.

We have the same problem with Z.Dapper.Plus 3.0.0 using Oracle 11g.
We tried reverting back to an older version (Z.Dapper.Plus 2.0.12) and the problem was solved.

In our situation the problem as only arised when we use a Also/Then bulk insert, but we haven't had the occasion to test other situations as of yet.

@JonathanMagnan
Copy link
Member

Hello @jspinella and @yfunck-vix ,

Yes, you are both right, the v3.0.0 added an error in our code.

The issue happened when an entity type has no mapping defined. A constructor that now require a parameter since v3.0.0 was called without the parameter.

The issue is now fixed in v3.0.1


In your case @jspinella ,

You will still need to provide an explicit mapping to make your project work as your destination table name is not the same as the entity type name

DapperPlusManager.Entity<Animal>().Table("animals");

Let me know if the issue is solved in the latest version for both of you.

Best Regards,

Jon

@jspinella
Copy link
Author

This is a good reason to buy Dapper Plus (ability to revert to an earlier version) :P

@JonathanMagnan I use an attribute (e.g. [Table("Animals")]) on the Animal class, would this still work? Thank you!

@JonathanMagnan
Copy link
Member

Yup, Table attribute makes it works ;)

@yfunck-vix
Copy link

We've been able to test it on our side, and it seems it's working fine with the 3.0.1 version. (In our case our destination table and entity had the same name).

@JonathanMagnan
Copy link
Member

Awesome ;)

Thank for letting us know.

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

No branches or pull requests

3 participants