Dapper.PartialUpdate adds a Partial<T> wrapper and Dapper extension methods that only send explicitly-set fields during INSERT and UPDATE.
Use this when you need patch-style updates/inserts:
- Sometimes you send a full model.
- Sometimes you need to omit fields so they are not written at all.
Partial<T> tracks whether a value has been set (IsSet), and extensions build SQL using only those set fields.
dotnet add package Dapper.PartialUpdateusing System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Dapper.PartialUpdate;
[Table("Fixture")]
public sealed class Fixture
{
[Key]
public int Id { get; set; }
public Partial<int> FixtureType { get; set; }
public Partial<string?> Name { get; set; }
}var fixture = new Fixture { Id = 12 };
fixture.Name = "Updated Name"; // marks IsSet = true
fixture.FixtureType = 3; // marks IsSet = true
await connection.UpdatePartialsAsync(fixture, tx);Only Name and FixtureType are included in the SET clause.
var p = new Partial<string>("abc"); // IsSet = true
p.Unset(); // IsSet = false
p.Value = "xyz"; // IsSet = trueYou can also assign directly with implicit conversion:
entity.Name = "Alice"; // Partial<string> IsSet=trueDapperPartialExtensions provides:
UpdatePartials<T>(...)UpdatePartialsAsync<T>(...)InsertPartials<T>(...)InsertPartialsAsync<T>(...)
- Table name from
[Table]or class name. - Key from
[Key], orId, or{TypeName}Id. - Column names from
[Column]or property name. - Only
Partial<T>properties withIsSet == trueare updated. - If no fields are set, update returns
0without executing SQL.
- Only set
Partial<T>properties are included. - If no partial fields are set, executes
INSERT ... DEFAULT VALUES.
.\pack.ps1Override version:
.\pack.ps1 -Version 0.1.1Packages are written to artifacts\nuget.