DapperLib / DapperLib/Dapper.Contrib
Handling RowVersion for optimistic concurrency during update
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
The database we are operating against uses optimistic concurrency via the MS SQL TIMESTAMP column type. This derails using Update without some complete faff of custom SQL to handle the situation.
I have forked the repo and done a first-pass implementation of supporting a new RowVersion attribute here: https://github.com/RaringCoder/Dapper
It is bundled in with some aesthetic changes, an update to how property caching works, and some code de-duplication.
The current implementation simply adds the version to the WHERE clause on update, resulting in nothing updated if the version differs. This does what I need, crudely. RowVersionAttribute can be applied to any columns, but so far I only support one. Column type doesn't matter. It is automatically excluded from inserts (possibly overridden by Write(true) if the database doesn't handle version for you?).
Before I go for a full PR, I want some advice on how better to handle a concurrency collision other than simply not updating any rows (the current implementation). My prevailing theory is something akin to how Insert currently works in that, per adaptor, we do a query to select any database-generated Ids. We could do something similar and select a flag out when checking if the version changed:
SELECT COUNT(1) AS VersionHasChanged FROM Table WHERE Key = @key AND Version <> @version
I will be using my fork locally to make progress on the app I'm working on, but I'd like to get this baked in to Contrib properly.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed RowVersion implementation in the linked RaringCoder/Dapper fork and comparing it with Dapper.Contrib's update and insert behavior. Clarify the desired concurrency-collision behavior and database scope with maintainers; done means an agreed design, implementation, and tests covering version-aware updates and inserts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100