Add UpdateMultiple for bulk updates - #320
Open
henkmollema wants to merge 1 commit into
Open
Conversation
Add UpdateMultiple/UpdateMultipleAsync extension methods that issue a single UPDATE ... SET ... WHERE statement, modeled on EF Core's ExecuteUpdate. The properties to assign are described with a fluent SetProperty chain (constant values or column-referencing value selectors); the rows are filtered with a LINQ predicate. Both the set-clause and where-clause are built from a single SqlExpression instance so their parameters share numbering, and the SqlExpression visitor now translates arithmetic operators. Assignment targets are emitted unqualified for cross-database compatibility.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Adds
UpdateMultiple<T>/UpdateMultipleAsync<T>extension methods for bulk updates, modeled on EF Core''sExecuteUpdatebut kept simple and consistent with the rest of the Dommel API. They issue a singleUPDATE ... SET ... WHEREstatement without loading entities first.The properties to assign are described with a fluent
SetPropertychain — either a constant value or a value selector that may reference entity columns and use arithmetic. Rows are filtered with a LINQ predicate. The methods return the number of affected rows (matchingDeleteMultipleandExecuteUpdate), and both sync and async variants are provided.Implementation notes
SetPropertyCalls<TEntity>fluent builder with bothSetPropertyoverloads (constant value + value selector).SqlExpressioninstance (obtained via theSqlExpressionFactory) builds both the set-clause and where-clause, so their auto-numbered parameters share numbering and never collide — and the where-clause stays JSON-aware underDommel.Json.SqlExpressionnow translates arithmetic operators (+ - * / %), enabling value selectors likep => p.Stock - 1(also usable inWhere).set [FullName] = ...) while where-clause columns stay qualified — some databases (e.g. Postgres) reject a table-qualified assignment target.Known limitations (documented in XML comments)
column op constantarithmetic;column op columnis not supported (consistent with existingWherebehavior).Testing
Dommel.Tests: 206 passed (incl. newUpdateTestsSQL-generation cases across SQL Server / MySQL / Postgres and an arithmetic-in-Whereregression test); no regressions from the arithmetic-routing change.Dommel.Json.Tests: 35 passed.[ClassData(typeof(DatabaseTestData))]pattern (require local SQL Server / MySQL / PostgreSQL; not run in this environment).