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 34 forks source link

BulkMerge with Postgres Not Working as Expected #57

Closed rajkamal0610 closed 4 years ago

rajkamal0610 commented 4 years ago

With the help of this url https://bulk-operations.net/online-examples/cODwTM, I tried to do same in postgres. Kindly help me about the issue

NpgsqlConnection connection = new NpgsqlConnection(connString); connection.Open();

        DataTable dtCustomers = new DataTable("Customers");

        dtCustomers.Columns.Add("CustomerID", typeof(int));
        dtCustomers.Columns.Add("Name", typeof(string));
        //dtCustomers.Columns.Add("Description", typeof(string));

        for (int i = 0; i < 10; i++)
        {
            // Add very customer twice with the same "CustomerID"
            {
                var drCustomer = dtCustomers.NewRow();
                drCustomer["CustomerID"] = (i + 1);  
                drCustomer["Name"] = "Customer_" + i;
                //drCustomer["Description"] = "Customer_Desc_" + i;
                dtCustomers.Rows.Add(drCustomer);
            }

            {
                var drCustomer = dtCustomers.NewRow();
                drCustomer["CustomerID"] = (i + 1);  
                drCustomer["Name"] = "Customer_" + i;
               // drCustomer["Description"] = "Customer_Desc_" + i;
                dtCustomers.Rows.Add(drCustomer);
            }
        }

        // SAVE customers
        using (var bulk = new BulkOperation(connection))
        {
            bulk.DestinationTableName = "Customers";
            //bulk.AllowUpdatePrimaryKeys = true;
            //bulk.BatchSize = 1000;
            //bulk.AutoMapKeyName = "Name;Description";
            bulk.AllowDuplicateKeys = true;
            bulk.InsertIfNotExists = true;

            bulk.BulkMerge(dtCustomers);
        }
JonathanMagnan commented 4 years ago

Hello @rajkamal0610 ,

Unfortunately, some options are not supported by some providers such as PostgreSQL.

We will look if that's the case and if there is something we can do.

Best Regards,

Jon

rajkamal0610 commented 4 years ago

Thanks for the reply. But we really need the option to do

JonathanMagnan commented 4 years ago

Hello @rajkamal0610 ,

Just to let you know that the first version of the fix passed the code review.

We will test it again and everything is fine, it will be released tomorrow.

rajkamal0610 commented 4 years ago

Okay. Thanks for the actions. Also I found some issue on bulkmerge in postgres. Am preparing sample project with details

JonathanMagnan commented 4 years ago

Hello @rajkamal0610 ,

The v3.0.16 has been released.

Could you try it and let us know if that's working?

If you wish to send the project sample in private, you can send it here: info@zzzprojects.com

rajkamal0610 commented 4 years ago

Hi Jonathan,

Thanks for the fix.

I have tested with basic functionality and use cases, all are working fine in testing environment.

Will implement in production environment and let you know if any issue or need help from you

JonathanMagnan commented 4 years ago

Awesome @rajkamal0610

we are glad everything is working out for you!

Don't hesitate to contact us once you implement it :)

Have a great day,

Jon

JonathanMagnan commented 4 years ago

Hello @rajkamal0610 ,

A simple reminder that we are here to assist you!

feel free to contact us once you implement it.

Looking forward to hearing from you,

Jon