CoreOne.ModelPatch 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CoreOne.ModelPatch --version 1.2.2
                    
NuGet\Install-Package CoreOne.ModelPatch -Version 1.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CoreOne.ModelPatch" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreOne.ModelPatch" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="CoreOne.ModelPatch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CoreOne.ModelPatch --version 1.2.2
                    
#r "nuget: CoreOne.ModelPatch, 1.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CoreOne.ModelPatch@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CoreOne.ModelPatch&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=CoreOne.ModelPatch&version=1.2.2
                    
Install as a Cake Tool

CoreOne.ModelPatch

A lightweight and flexible library for applying partial updates to entities in .NET Core and EF Core. Ideal for scenarios where PATCH operations are needed, such as RESTful APIs.

πŸš€ Features

  • Apply partial updates to EF Core entities using JSON Patch-like syntax
  • Supports nested properties and complex object graphs
  • Easy integration with ASP.NET Core Web APIs
  • Reduces boilerplate code for update operations
  • Respect unique index contrainsts while inserting objects

πŸ“¦ Installation

Install via NuGet:

dotnet add package CoreOne.ModelPatch

Or via the NuGet Package Manager:

Install-Package CoreOne.ModelPatch

πŸ› οΈ Usage

1. Define Your Entity

public class User
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string OtherField { get; set; }
    public Address Location { get; set; }
    public ICollection<Tag> Tags { get; set; }
}

public class Address
{
    public string City { get; set; }
    public string Country { get; set; }
}

[Index(nameof(Value), IsUnique = true)]
public class UserTag
{
    public int Id { get; set; }
    public int UserId { get; set; }
    public string Value { get; set; }

    public User? User { get; set; }
}

2. Create a Patch Model

var model = new User {
    Name = "John",
    Locaion = new Address {
        City = "New York",
        Country = "USA"
    },
    Tags = new List<Tag> {
        new UserTag { Value = "tag1" } // this record is added
        new UserTag { Value = "tag1" } // this one will be ignored
        new UserTag { Value = "tag2" } // this record is added
    }
};

3. Apply the Patch

Only fields present in the delta model are updated, if certain fields are not available then that field does not get the update.

var delta = model.ToDelta();
delta.Remove("OtherField");
var dataService = new DataModelService<YourContext>(IServiceProvider instance, yourContextInstance);
var result = await dataService.Patch(delta);

This will update the Name and Location.City properties of the User entity.

πŸ§ͺ Sample API Endpoint

private readonly DataModelService _dataService;

public UserController(DataModelService dataService) => _dataService = dataService;

[HttpPatch("{id}")]
public async Task<IActionResult> PatchUser(int id, [FromBody] Delta<User> patchData, CancellationToken cancellationToken)
{
    var result = await _dataService.Patch(delta, cancellationToken);
    return Updated(result);
}

πŸ“š Documentation

The library uses reflection to traverse and update properties. It’s designed to be intuitive and extensible for most EF Core scenarios.

🀝 Contributing

Feel free to fork the repo, submit issues, or open pull requests. Contributions are welcome!

πŸ“„ License

This project is licensed under the MIT License.


Would you like help writing unit tests or integrating this into a specific project?

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 24 4/7/2026
1.3.0 38 4/7/2026
1.2.5 103 1/26/2026
1.2.4 183 10/2/2025
1.2.3 187 9/30/2025
1.2.2 184 9/30/2025
1.2.1 141 9/26/2025
1.2.0.1 186 9/25/2025
1.2.0 183 9/23/2025
1.1.0 184 7/17/2025
1.0.0 184 5/9/2025