zzzprojects / EntityFramework-Extensions

Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
https://entityframework-extensions.net
346 stars 57 forks source link

Bulk Merge does not exists and BulkInsert Options dont have "InsertIfNotExists" #607

Closed lucas-fsousa closed 1 week ago

lucas-fsousa commented 1 week ago

Description

Hello. I'm having trouble using the EF extension library for BULK INSERT and BULK MERGE.

My objective is to insert a massive amount of information from a table that in turn has thousands of records, but these records cannot be duplicated in any way. I have a Unique Index that does the job of avoiding duplication.

When using BulkInsert according to the documentation at https://entityframework-extensions.net/bulk-insert

If I send my data using

context.BulkInsert(data)

and there are any duplicate records, an exception will occur as I expect it to happen.

The documentation contains an example

context.BulkInsert(customers, options => { 
    options.InsertIfNotExists = true;
    options.PrimaryKeyExpression = customer => customer.Code;
  });

I replicated the same to do some tests and

options.InsertIfNotExists = true;
options.PrimaryKeyExpression = customer => customer.Code

Does not exist in BulkConfig

See here a capture I made of the example copied directly from the documentation. I looked for any nuget packages that might be missing, but I didn't find anything. Any idea what it is? imagem_2024-10-09_185413207

As I had no success with BulkInsert, I looked for BulkMerge which would possibly solve my problem using this topic https://entityframework-extensions.net/bulk-merge#bulk-merge-with-options. But to my surprise, BulkMerge doesn't exist in the package. See the image below. imagem_2024-10-09_190134181

Further technical details

JonathanMagnan commented 1 week ago

Hello @lucas-fsousa ,

You are currently using the wrong package.

Unfortunately, this other paid package chose a name that is very similar to ours, which confuses a lot of people.

You can find our package here: https://www.nuget.org/packages/Z.EntityFramework.Extensions.EFCore/

Make sure to use the latest v8.x of our package (currently v8.103.5) (the first number but correspond to your EF Core version).

Let me know if that solves your issue.

Best Regards,

Jon

lucas-fsousa commented 1 week ago

It seems to be working well! I will do some tests to see if the problem will be resolved.

But for this case. It's all right. Thanks!