DapperLib / DapperLib/Dapper.Contrib

InsertOnly and UpdateOnly idea

Open
#134 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Description

Hey,

So I've been playing with the idea of adding a few extra Update and Insert methods which allow you to pick properties that you want to update, rather that attempting to update all the properties.

The use case would be you want to make an atomic change without fetching the data before hand. Example

user.Name = "Dave";
user.Age = 43;
Assert.True(await connection.UpdateOnlyAsync(user, includedFields: x => x.Age).ConfigureAwait(false)); //returns true if updated, based on tracking
user = await connection.GetAsync<IUser>(id).ConfigureAwait(false);
Assert.Equal("Bob", user.Name); // Name isn't updated
Assert.Equal(43, user.Age);     // Age is updated

It's essentially the same as the existing Update method with the extra includeFields params

params Expression<Func<T, object>>[] includedFields

and the code which currently fetches all the properties from the T is swapped out for something which walks this list..

I have put together a draft PR https://github.com/DapperLib/Dapper.Contrib/pull/133 just so you can see what I mean.. and to get feedback on if this idea is in keeping with the project or not.. also for guidence if it's not as to a way to contirbute back somehow..

The PR only contains an example of UpdateAsync.. but it would be easy enough to add the others.. and also remove the duplication.

Would love to hear you thoughts on this.

Thanks Dave

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Update methods and draft PR #133, which demonstrates the proposed UpdateAsync approach. Compare the requested UpdateOnly and InsertOnly variants with current behavior and determine the needed includedFields API. Done means the supported variants update or insert only the selected properties and have coverage for the shown atomic-use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.