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
<PackageReference Include="DKNet.EfCore.DtoGenerator" Version="10.1.19"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="DKNet.EfCore.DtoGenerator" Version="10.1.19" />
<PackageReference Include="DKNet.EfCore.DtoGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add DKNet.EfCore.DtoGenerator --version 10.1.19
#r "nuget: DKNet.EfCore.DtoGenerator, 10.1.19"
#:package DKNet.EfCore.DtoGenerator@10.1.19
#addin nuget:?package=DKNet.EfCore.DtoGenerator&version=10.1.19
#tool nuget:?package=DKNet.EfCore.DtoGenerator&version=10.1.19
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. - Validation attribute copy-through —
System.ComponentModel.DataAnnotationsattributes on entity properties are copied to the generated DTO properties. [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, 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: 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 |
|---|---|---|
| 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 |