Implement bulk update with SaveChanges
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
When multiple identical updates are performed on different rows via SaveChanges, we currently generate N SQL UPDATEs:
```sql
UPDATE foo SET bar = @v1 WHERE id = @id1;
UPDATE foo SET bar = @v2 WHERE id = @id2;
UPDATE foo SET bar = @v3 WHERE id = @id3;
...
```
We could explore identifying such identical updates and collapsing them into a single UPDATE statements, e.g.:
```sql
UPDATE foo
SET bar = CASE
WHEN id = @id1 THEN @v1
WHEN id = @id2 THEN @v2
WHEN id = @id3 THEN @v3
...
END
WHERE "Id" IN (@id1, @id2, @id3);
```
We'd need to explore how this actually performs across different databases etc. This is conceptually similar to what we already do for SQL Server for insertion (where multiple INSERTs are collapsed to a single MERGE), and to #27550 for bulk deletion.
Contributor guide
Assessment
This issue has not been assessed yet.