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

Dapper.plus integration with Noda Time library. #78

Closed carlos0202 closed 3 years ago

carlos0202 commented 3 years ago

Hi folks, thanks for all the hard work.

I've just found an issue while bulk inserting information using LocalDateTime from Noda Time. Basically, I have a nullable timestamp without time zone column on my Postgres database, and the bulk insert is inserting a null value regardless of the entity values contained on the collection I'm inserting.

Can I make Dapper.Plus to play nice with Noda Time?

Thanks in advance for your help!!!

JonathanMagnan commented 3 years ago

Hello @carlos0202 ,

Can you give us a small example of how you use Noda Time? We never really used this library so we want to make sure we use it right. You can send the project in private here if you need: info@zzzprojects.com

I might be wrong but mapping it and converting it to a normal DateTime might be the easiest solution:

DapperPlusManager.Entity<EntitySimple>().Table("EntitySimples").Map(x => x.DateTimeProperty.ToMethodThatConvertToNormalDateTime(), "DateTimeColumn")

Best Regards,

Jon

carlos0202 commented 3 years ago

Hello @carlos0202 ,

Can you give us a small example of how you use Noda Time? We never really used this library so we want to make sure we use it right. You can send the project in private here if you need: info@zzzprojects.com

I might be wrong but mapping it and converting it to a normal DateTime might be the easiest solution:

DapperPlusManager.Entity<EntitySimple>().Table("EntitySimples").Map(x => x.DateTimeProperty.ToMethodThatConvertToNormalDateTime(), "DateTimeColumn")

Best Regards,

Jon

Hi, Actually, we use it on a Postgres database for reporting purposes, and I think converting it into DateTime will not be accepted. The weird thing while using Dapper.Plus is that it didn't throw an error, and our low-level NpgSqlConnection has the wrappers to handle Noda Time types, so the issue is that the value is being inserted as null in all the cases but no error is thrown.

In our solution, we have a factory that provides a connection with the NodaTime Handlers already added: image

We have a simple entity configuration: image

And finally, we call the Batch insert of the information: image

The entity configuration method is called on the constructor of the same class.

Entity relevant property is the following: image

So, that's our actual use case, and we just need Noda Time to integrate with Dapper (Dapper.Plus). Thanks in advance for your help!

carlos0202 commented 3 years ago

I've tried registering a type mapper but nothing different happened. How type mapping is handled by Dapper.Plus when doing batch operations? How can we register a custom type mapper as we do on regular Dapper?

carlos0202 commented 3 years ago

@JonathanMagnan anything else you can reach me out privately. We got a license this month and started switching to use Dapper.Plus batch operations and we really need to work on it while using Noda Time for better date/time handling.

carlos0202 commented 3 years ago

Hello @carlos0202 ,

Can you give us a small example of how you use Noda Time? We never really used this library so we want to make sure we use it right. You can send the project in private here if you need: info@zzzprojects.com

I might be wrong but mapping it and converting it to a normal DateTime might be the easiest solution:

DapperPlusManager.Entity<EntitySimple>().Table("EntitySimples").Map(x => x.DateTimeProperty.ToMethodThatConvertToNormalDateTime(), "DateTimeColumn")

Best Regards,

Jon

I've tried your approach and got the expected error of sending regular BCL types when the project is configured to use Noda Time. So, I need Dapper.Plus to work with Noda Time and the problem seems to be on a low-level implementation.

JonathanMagnan commented 3 years ago

Hello @carlos0202 ,

My developer will look at it tomorrow to see what's possible to do with your requirement.

JonathanMagnan commented 3 years ago

Hello @carlos0202 ,

The v3.0.32 has been released.

We now support the following type: NodaTime.LocalDateTime

If there are some other types, let us know and we will add it.

Best Regards,

Jon

carlos0202 commented 3 years ago

Hello @carlos0202 ,

The v3.0.32 has been released.

We now support the following type: NodaTime.LocalDateTime

If there are some other types, let us know and we will add it.

Best Regards,

Jon

Ok @JonathanMagnan ,

I'll try next Monday and I'll close this ticket if everything is correct. One question though, did you added support for just 1 type of the library or to all the types? Thanks in advance for the help.

carlos0202 commented 3 years ago

Hi @JonathanMagnan ,

I've just tested with the new version and it works as expected. Thanks for all the good work. Closing this issue. Cheers!!!