DKNet

Choose DTO properties

Part of DKNet.EfCore.DtoGenerator. Using the Quick Start entity, replace the DTO shell with an explicit allow-list and adjust its initializer to omit Price:

[GenerateDto(typeof(Product), Include = new[] { nameof(Product.Id), nameof(Product.Name) })]
public partial record ProductDto;

Public readable entity properties pass through Include or the combined local and global exclusions, then navigation filtering determines the generated property set.

For an ordinary [GenerateDto] DTO, a non-empty Include bypasses global exclusions and navigation filtering. Otherwise local and global exclusion names are combined, and the effective IgnoreComplexType selects whether navigation-like properties are omitted.

⚙️ Configuration reference

Option Type Default Effect
entityType Type constructor argument Required Entity whose properties are inspected.
Include string[] Empty Non-empty allow-list; mutually exclusive with non-empty Exclude.
Exclude string[] Empty Local property names removed alongside global names.
IgnoreComplexType bool attribute argument Unset, then project value, then true Omit navigation-like properties unless explicitly disabled.
DtoGeneratorExclusions MSBuild string Unset Comma/semicolon-separated, trimmed names excluded project-wide.
DtoGeneratorIgnoreComplexType MSBuild boolean Unset Default for DTOs without an explicit attribute value; an unparseable value falls through to true.

Add project defaults inside a .csproj property group:

<PropertyGroup>
  <DtoGeneratorExclusions>CreatedBy,UpdatedBy</DtoGeneratorExclusions>
  <DtoGeneratorIgnoreComplexType>true</DtoGeneratorIgnoreComplexType>
</PropertyGroup>

The package exposes both switches to the compiler automatically. See the Global Exclusions Guide for project-wide setup.

🧱 Where it fits

The compiler reads project defaults and per-DTO arguments, then DtoGenerator emits only the selected DTO members.

Defaults are compile-time inputs; there is no DI registration or runtime options object.

⚠️ Gotchas & limits