zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 36 forks source link

BulkInsert/BulkMerge in combination with Npgsql (PostgreSQL) has weird behaviour #59

Closed isenmann closed 3 years ago

isenmann commented 3 years ago

Hi, I have the following problem in trying to BulkInsert several entities into a table. The code looks like this:

[Table("Properties")]
[Serializable]
public class Property
{
    public long ID { get; set; }
    public string PropertyGroup { get; set; }
    public string TranslationKey { get; set; }
    public int GroupOrder { get; set; }
    public int Order { get; set; }
}

.
.
.
DapperPlusManager.Entity<Property>().Table("Properties");
DapperPlusManager.Entity<Property>().Identity(x => x.ID);
DapperPlusManager.Entity<Property>().Key(x => x.ID);
.
.
.
using (var dapperDb = new NpgsqlConnection(_connectionString))
{
    dapperDb.Open();
    await dapperDb.BulkActionAsync(x => x.BulkInsert(insert));  // also x.BulkMerge(insert) do the same behaviour
}

'insert' is just a list of 50 elements of the class Property, the ID is set to 0 for every object before bulkinsert ist called.

After executing the code above, only the last element of that list is inserted into the DB table and no other element. Calling the method again, then the same behaviour applies as described, only the last element is added to the DB table and so on. So I have to call the method 50 times to add all elements which is definitely not intended.

Is there some special option in dapper to get this working with Npgsql? Or do I have to set something special in the PostgreSQL database to get the Bulk methods work?

Versions I used:

JonathanMagnan commented 3 years ago

Hello @isenmann ,

This is indeed a strange behavior and not an intended one.

Is it possible to provide a runnable project that contains only this issue? You can send it in private here: info@zzzprojects.com

I just tried a similar scenario as yours and all entities were inserted correctly, so I probably miss a little piece of the puzzle to get the same behavior as you.

Best Regards,

Jon

isenmann commented 3 years ago

Hi @JonathanMagnan , I will try to strip down the project or to demonstrate this behaviour in a new project. I'm not allowed to share the current project with you. I will let you know as soon as I have a stripped down project or a demo project.

Thanks for your answer.

Best Regards, Daniel

isenmann commented 3 years ago

Hi @JonathanMagnan ,

the demo project was sent to the email you have provided. Waiting for your feedback.

Best Regards, Daniel

isenmann commented 3 years ago

Any news on this bug?

Thanks Daniel

JonathanMagnan commented 3 years ago

Hello @isenmann ,

Thank for the reminder, it looks like the issue was lost in our system.

My developed coded the solution 3 weeks ago so I will sure review it asap tomorrow and make sure we don't lose track of it again!

I will keep you updated very soon.

JonathanMagnan commented 3 years ago

Hello @isenmann ,

A new version has been released today,

Could you try it and let me know if the issue has been fixed correctly?

isenmann commented 3 years ago

Hello @JonathanMagnan, Great, thanks for this fast reply. 👍🏻 I will test it tomorrow and will let you know about the result.

isenmann commented 3 years ago

It's working! Don't see any error now. Thanks a lot for this fast solution. Keep up the good work