zzzprojects / Dapper-Plus

Dapper Plus - High-Efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET
https://dapper-plus.net/
383 stars 85 forks source link

Null reference exception on BulkInsert #58

Closed jspinella closed 4 years ago

jspinella commented 4 years ago

Essentially I am experiencing https://github.com/zzzprojects/Dapper-Plus/issues/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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Yup, Table attribute makes it works ;)

yfunck-vix commented 4 years ago

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 commented 4 years ago

Awesome ;)

Thank for letting us know.