TortugaResearch / DotNet-ORM-Cookbook

This repository is meant to show how to perform common tasks using C# with variety of ORMs.
https://tortugaresearch.github.io/DotNet-ORM-Cookbook/
The Unlicense
345 stars 29 forks source link

Use case: Advanced Bulk Operations #174

Open mikependon opened 4 years ago

mikependon commented 4 years ago

This use case covers:

mikependon commented 4 years ago

This is a very important scenario. I would humbly say, the Bulk Delete, Bulk Merge, Bulk Update must be presented as well :)

Grauenwolf commented 4 years ago

24 covers Bulk Insert.

Let's rename this one "Advanced Bulk Operations" to cover the other scenarios.

FransBouma commented 4 years ago

This is formulated too vaguely: are these operations on sets inserted in a temptable first (merge suggests that) or is e.g. bulk update a single update statement that affects multiple rows? (same for delete)

mikependon commented 4 years ago

For BulkInsert, simply call the SqlBulkCopy.WriteToServer. For Bulk Merge/Update/Delete, bulk insert first on the pseudo-table then execute a Merge/Update/Delete via JOIN statement.

Grauenwolf commented 4 years ago

I don't know about the other ORMs.

FransBouma commented 4 years ago

LLBLGen Pro can't do this either. Well, I can build it with the plainsql API I have of course.

The bulk delete/updates using a single delete/update statement is a scenario that is used way more often than this tho. In 18 years I've never had a single request to build in bulk merge/update using a temp table.

Grauenwolf commented 4 years ago

So you mean like 'DELETE FROM Table WHERE ...`?

If so, that's going to be #104.

FransBouma commented 4 years ago

yes, and update table set ... where <predicate> which affects multiple rows. Bonus points if you can also support row filtering based on related entities :)

mikependon commented 4 years ago

Was not it more faster to bring the data in Bulk within the DB server and do the operation there utilizing the correct index (specially the clustered index)? With pseudo temp table, this can be achieved. But you it is correct that this is not a common scenario.