DKNet.EfCore.DtoGenerator
13.2.5
dotnet add package DKNet.EfCore.DtoGenerator --version 13.2.5
NuGet\Install-Package DKNet.EfCore.DtoGenerator -Version 13.2.5
<PackageReference Include="DKNet.EfCore.DtoGenerator" Version="13.2.5"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="DKNet.EfCore.DtoGenerator" Version="13.2.5" />
<PackageReference Include="DKNet.EfCore.DtoGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add DKNet.EfCore.DtoGenerator --version 13.2.5
#r "nuget: DKNet.EfCore.DtoGenerator, 13.2.5"
#:package DKNet.EfCore.DtoGenerator@13.2.5
#addin nuget:?package=DKNet.EfCore.DtoGenerator&version=13.2.5
#tool nuget:?package=DKNet.EfCore.DtoGenerator&version=13.2.5
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))]— generatesinit-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;Includetakes only the listed properties).IgnoreComplexType— flattens out navigation-style properties by default; per-DTO or project-wide (DtoGeneratorIgnoreComplexType) override.- Global exclusions (
DtoGeneratorExclusionsMSBuild property) — exclude the same properties (e.g. audit columns) across every DTO in the project. - Attribute copy-through —
System.ComponentModel.DataAnnotationsattributes on entity properties are copied to the generated DTO properties, as is[SensitiveData(...)]fromDKNet.EfCore.Abstractions(with its role arguments, and emitted as the bare[SensitiveData]when no role is named). You declare a property sensitive once, on the entity; every generated response model carries it. Attributes from any other namespace are not copied. [RaisesEvent]build-time validation — a second generator in this package validatesDKNet.EfCore.Abstractions.Events.RaisesEventAttributedeclarations 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/classtypes with no base type or interface, and nothing on them but the copied attributes above. A DTO that carries[SensitiveData]needsDKNet.EfCore.Abstractionsreferenced; the generator itself still references no DKNet package, matching the attribute by namespace and name only.
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: DKDTOGEN001–DKDTOGEN005 from the DTO generator, and DKRAISEVT001–DKRAISEVT011 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
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 |
|---|---|---|
| 13.2.5 | 180 | 10/2/2026 |
| 13.2.4 | 79 | 10/1/2026 |
| 13.2.3 | 84 | 10/1/2026 |
| 13.2.2 | 88 | 10/1/2026 |
| 13.2.1 | 88 | 10/1/2026 |
| 13.2.0 | 92 | 10/1/2026 |
| 13.1.3 | 126 | 9/21/2026 |
| 13.1.2 | 356 | 9/18/2026 |
| 13.1.1 | 98 | 9/18/2026 |
| 13.1.0 | 85 | 9/18/2026 |
| 13.0.2 | 88 | 9/18/2026 |
| 13.0.1 | 102 | 9/18/2026 |
| 13.0.0 | 108 | 9/18/2026 |
| 12.0.0 | 97 | 9/17/2026 |
| 11.0.0 | 174 | 9/17/2026 |
| 10.1.29 | 130 | 9/17/2026 |
| 10.1.28 | 87 | 9/17/2026 |
| 10.1.27 | 86 | 9/16/2026 |
| 10.1.26 | 151 | 9/16/2026 |
| 10.1.25 | 88 | 9/16/2026 |