DKNet.EfCore.DtoGenerator 10.1.19

dotnet add package DKNet.EfCore.DtoGenerator --version 10.1.19
                    
NuGet\Install-Package DKNet.EfCore.DtoGenerator -Version 10.1.19
                    
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="DKNet.EfCore.DtoGenerator" Version="10.1.19">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.EfCore.DtoGenerator" Version="10.1.19" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.EfCore.DtoGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 DKNet.EfCore.DtoGenerator --version 10.1.19
                    
#r "nuget: DKNet.EfCore.DtoGenerator, 10.1.19"
                    
#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 DKNet.EfCore.DtoGenerator@10.1.19
                    
#: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=DKNet.EfCore.DtoGenerator&version=10.1.19
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.EfCore.DtoGenerator&version=10.1.19
                    
Install as a Cake Tool

DKNet.EfCore.DtoGenerator

A Roslyn incremental source generator that emits DTO properties from an entity type at compile time. Declare an empty partial record, apply [GenerateDto(typeof(Entity))], and the generator mirrors the entity's public readable properties onto it — no hand-written mapping boilerplate, no runtime reflection, and no runtime dependency on this package.

Install

<ItemGroup>
  <PackageReference Include="DKNet.EfCore.DtoGenerator" Version="{latest}" PrivateAssets="all" OutputItemType="Analyzer" />
</ItemGroup>

Features

  • [GenerateDto(typeof(Entity))] — generates init-only properties for every public instance readable property of the entity, following the entity's inheritance chain.
  • Exclude / Include — per-DTO property filtering (mutually exclusive; Include takes only the listed properties).
  • IgnoreComplexType — flattens out navigation-style properties by default; per-DTO or project-wide (DtoGeneratorIgnoreComplexType) override.
  • Global exclusions (DtoGeneratorExclusions MSBuild property) — exclude the same properties (e.g. audit columns) across every DTO in the project.
  • Validation attribute copy-throughSystem.ComponentModel.DataAnnotations attributes on entity properties are copied to the generated DTO properties.
  • [RaisesEvent] build-time validation — a second generator in this package validates DKNet.EfCore.Abstractions.Events.RaisesEventAttribute declarations against their [GenerateDto] payloads, and generates the payload record for the attribute's convention forms, named by fixed convention (entity name + optional label + narrowing properties + operations + Event).
  • Zero runtime coupling — generated DTOs are plain record/class types with no base type, interface, or attribute left on them.

Quick start

public class Product
{
    public Guid Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
}

using DKNet.EfCore.DtoGenerator;

[GenerateDto(typeof(Product))]
public partial record ProductDto;

This emits ProductDto.g.cs with Id, required string Name, and Price as init-only properties.

Customisation reference

Everything is compile-time: attribute arguments and MSBuild properties. There is nothing to register at runtime.

[GenerateDto]AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, not inherited:

Member Type Default Effect
entityType (ctor arg) Type required The entity to mirror, as typeof(Entity).
Exclude string[] [] Property names to omit. Combined with the project-wide exclusions. Mutually exclusive with Include.
Include string[] [] When non-empty, only these properties are generated — local Exclude, the global list and IgnoreComplexType are all bypassed.
IgnoreComplexType bool unset → project-wide value → true When effectively true, navigation-style properties are dropped.

MSBuild properties, set in the consuming .csproj:

Property Default Effect
DtoGeneratorExclusions unset Comma/semicolon-separated property names excluded from every DTO in the project, and from [RaisesEvent] convention-form payloads. Already exposed to the compiler by this package.
DtoGeneratorIgnoreComplexType unset → built-in true Project-wide default for IgnoreComplexType when a DTO does not set it.
EmitCompilerGeneratedFiles / CompilerGeneratedFilesOutputPath unset Standard Roslyn switches for writing the generated .g.cs to disk for inspection.

Property selection, before any filter: every public instance property with a public getter and no index parameters, walked up the entity's base chain and de-duplicated by name.

Build diagnostics: DKDTOGEN001DKDTOGEN005 from the DTO generator, and DKRAISEVT001DKRAISEVT011 from the [RaisesEvent] validator. The full table, with severity and meaning for each, is in the docs page below.

Full documentation: https://github.com/baoduy/DKNet/blob/main/docs/EfCore/DKNet.EfCore.DtoGenerator.md

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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
10.1.19 61 9/3/2026
10.1.18 63 9/3/2026
10.1.17 61 9/3/2026
10.1.16 66 9/3/2026
10.1.15 119 9/1/2026
10.1.14 69 9/1/2026
10.1.13 82 8/31/2026
10.1.12 93 8/25/2026
10.1.11 93 8/24/2026
10.1.10 91 8/22/2026
10.1.9 105 8/22/2026
10.1.8 89 8/21/2026
10.1.7 100 8/21/2026
10.1.6 90 8/21/2026
10.1.5 160 8/20/2026
10.1.4 93 8/20/2026
10.1.3 83 8/19/2026
10.1.2 86 8/19/2026
10.1.1 83 8/19/2026
10.0.36 99 8/18/2026
Loading failed