RoyalCode.SmartCommands.EntityFramework 0.1.0

dotnet add package RoyalCode.SmartCommands.EntityFramework --version 0.1.0
                    
NuGet\Install-Package RoyalCode.SmartCommands.EntityFramework -Version 0.1.0
                    
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="RoyalCode.SmartCommands.EntityFramework" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RoyalCode.SmartCommands.EntityFramework" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="RoyalCode.SmartCommands.EntityFramework" />
                    
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 RoyalCode.SmartCommands.EntityFramework --version 0.1.0
                    
#r "nuget: RoyalCode.SmartCommands.EntityFramework, 0.1.0"
                    
#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 RoyalCode.SmartCommands.EntityFramework@0.1.0
                    
#: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=RoyalCode.SmartCommands.EntityFramework&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=RoyalCode.SmartCommands.EntityFramework&version=0.1.0
                    
Install as a Cake Tool

SmartCommands

SmartCommands is a family of .NET libraries that implements a command-pattern approach using source generators to eliminate boilerplate for handlers, DI registration, validation, unit of work, repository access, decorators, and HTTP endpoint mapping.

Projects target .NET 8, .NET 9, and .NET 10. The analyzer/generator targets .NET Standard 2.0.

  • Runtime: RoyalCode.SmartCommands — attributes and contracts for commands and handlers.
  • EF Core adapter: RoyalCode.SmartCommands.EntityFrameworkIUnitOfWorkAccessor<TContext> and IRepositoriesAccessor<TContext>.
  • WorkContext adapter: RoyalCode.SmartCommands.WorkContext — adapters and DI for IWorkContext.
  • Source Generator: RoyalCode.SmartCommands.Generators — creates handlers, DI wiring, find/edit flows, decorators pipeline, and HTTP mapping.

Features

  • Attribute-driven commands with generated handlers (I{Command}Handler, {Command}Handler).
  • Validation integration via HasProblems(out Problems?) and WithValidateModel.
  • Additional validation methods with CommandValidation (Order defaults to 10) and Result/Task<Result>/ValueTask<Result> short-circuiting.
  • Unit of Work and repositories via WithUnitOfWork<TContext> / WithDbContext / WithWorkContext.
  • Entity loading and editing with WithFindEntities<TContext> and EditEntity<TEntity,TId>.
  • Decorators pipeline with WithDecorators and IDecorator<TCommand, TResult>.
  • Minimal APIs mapping using MapPost/Put/Patch/Delete/Get, metadata (WithSummary, WithDescription, WithAuthorization, WithPolicy, WithTags), created/accepted location (MapCreatedRoute, MapAcceptedRoute — the 202 location is optional), response composition (MapIdResultValue, MapResponseValues), explicit success status (WithResultStatus: Ok/Created/Accepted/NoContent), and repeatable endpoint filters (WithEndpointFilter<TFilter>).
  • Consistent results and problems modeling via SmartProblems (Result, Result<T>, Problems).

Compatibility

  • Commands: .NET 8, .NET 9, .NET 10.
  • Generator: .NET Standard 2.0.
  • Tested with Microsoft.NET.Test.Sdk 18.x; see RoyalCode.SmartCommands.Tests for coverage across sync/async, validate, decorators, find/edit, and mapping scenarios.

Installation

Add the packages you need:

  • RoyalCode.SmartCommands
  • RoyalCode.SmartCommands.EntityFramework (EF Core accessors)
  • RoyalCode.SmartCommands.WorkContext (WorkContext accessors)
  • RoyalCode.SmartCommands.Generators (analyzer/source generator)

RoyalCode.SmartCommands brings RoyalCode.SmartProblems.ApiResults transitively because Minimal API code generated by SmartCommands uses its HTTP result unions and ProduceProblems metadata. Add RoyalCode.SmartProblems.Http explicitly only when using its optional HTTP/filter integrations.

Quick start

  1. Define a partial command class with a method annotated with Command and required attributes.
  2. Implement HasProblems(out Problems?) when using WithValidateModel.
  3. Register Unit of Work adapters.
  4. Consume the generated handler interface via DI.

Example (create entity with validation + UoW):

using RoyalCode.SmartCommands;
using RoyalCode.SmartProblems;
using RoyalCode.SmartValidations;

public partial class CreateProduct
{
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }

    public bool HasProblems(out Problems? problems) =>
        Rules.Set<CreateProduct>()
            .NotEmpty(Name)
            .GreaterThanOrEqual(Price, 0)
            .HasProblems(out problems);

    [Command, WithValidateModel, WithUnitOfWork<MyDbContext>]
    public Result<Product> Execute()
    {
        var entity = new Product(Name, Price);
        return entity;
    }
}

EF Core registration:

services.AddUnitOfWorkAccessor<MyDbContext>();

WorkContext registration:

services.AddWorkContext<MyDbContext>()
    .AddUnitOfWorkAccessor<MyDbContext>();

HTTP mapping (Minimal APIs):

[MapPost("/", "CreateProduct")]
[MapGroup("api/products")]
[WithSummary("Create product")]
[WithDescription("Creates a new product")]
[MapCreatedRoute("{id}", nameof(Product.Id))]
public partial class CreateProduct { /* ... */ }

Guidance

  • Prefer returning Result/Result<T>; avoid exceptions for expected flows.
  • Use partial classes to enable WasValidated generation for null-state.
  • Do not mix WithUnitOfWork with WithDbContext/WithWorkContext on the same command.
  • EditEntity<TEntity,TId> requires UoW and the first method parameter typed as TEntity.
  • CancellationToken only in async methods.

Documentation

Tests

See RoyalCode.SmartCommands.Tests for scenarios covering:

  • Validation-first pipeline (WithValidateModel).
  • Additional validation ordering, DI, cancellation and short-circuiting.
  • Decorators sync/async with and without results.
  • Find entities and collections by id (MapFind) or by an alternate/composite key (MapFindBy<TEntity>), edit flows, and NotFound problems that name the entity.
  • Created and accepted responses with MapCreatedRoute, MapAcceptedRoute, MapIdResultValue, and MapResponseValues.
  • HTTP status selection, tags, endpoint filters, Find/Search and OpenAPI metadata.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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 is compatible.  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
0.1.0 49 7/20/2026
0.0.9 159 10/24/2025
0.0.8 139 10/3/2025
0.0.7 180 7/28/2025
0.0.6 179 7/28/2025