GrumpTech.EntityWebApi.Dtos
0.1.2
Prefix Reserved
dotnet add package GrumpTech.EntityWebApi.Dtos --version 0.1.2
NuGet\Install-Package GrumpTech.EntityWebApi.Dtos -Version 0.1.2
<PackageReference Include="GrumpTech.EntityWebApi.Dtos" Version="0.1.2" />
<PackageVersion Include="GrumpTech.EntityWebApi.Dtos" Version="0.1.2" />
<PackageReference Include="GrumpTech.EntityWebApi.Dtos" />
paket add GrumpTech.EntityWebApi.Dtos --version 0.1.2
#r "nuget: GrumpTech.EntityWebApi.Dtos, 0.1.2"
#:package GrumpTech.EntityWebApi.Dtos@0.1.2
#addin nuget:?package=GrumpTech.EntityWebApi.Dtos&version=0.1.2
#tool nuget:?package=GrumpTech.EntityWebApi.Dtos&version=0.1.2
EntityWebApi.Dtos
Part of EntityWebApi.
EntityWebApi.Dtos dynamically generates DTO types from Entity Framework Core entity models at runtime. Instead of maintaining separate DTO classes, you can generate them directly from your entities while controlling which properties are included through configuration and attributes.
Features
- Generate DTO types directly from Entity Framework Core models
- Configure suffixes
- Control included properties using attributes
- Create different DTO variants for read, create, update, and patch operations
- Automatically exclude generated properties for create/update DTOs
Getting started
Generate a standard DTO set
The following example creates DTO types for common operations:
var typeStore = new DtoBuilder()
.CreateKeyDtos(dataContext)
.CreateDtos(dataContext)
.CreatePostDtos(dataContext)
.CreatePutDtos(dataContext)
.CreatePutDtos<PatchDtoPropertyAttribute>(dataContext, false, "PatchDto")
.Build();
This generates:
| Method | Purpose |
|---|---|
CreateKeyDtos |
DTOs containing only key properties. |
CreateDtos |
Standard read DTOs. |
CreatePostDtos |
DTOs intended for create (POST) operations. |
CreatePutDtos |
DTOs intended for update (PUT) operations. |
CreatePutDtos<PatchDtoPropertyAttribute> |
Generates PATCH DTOs using a different property attribute and suffix. |
The resulting TypeStore contains all generated DTO types and can be used throughout the application.
Custom configuration
DTO generation can be customized using TypeConfiguration.
var typeStore = new DtoBuilder()
.CreateDtos(dbContext,
new TypeConfiguration
{
Suffix = "Dto",
NavigationSuffix = "Dto",
DefaultIncludes = EntityPropertyTypes.None,
IgnoreAttribute = EntityPropertyTypes.None,
SkipAutoGeneratedPropertiesOnAdd = true,
SkipAutoGeneratedPropertiesOnUpdate = true,
}
.SetAttributeType<TDtoPropertyAttribute>())
.Build();
Configuration options
| Property | Description |
|---|---|
Suffix |
Suffix appended to generated DTO type names. |
NavigationSuffix |
Navigation property DTOs are the DTOs ending with this suffix. |
DefaultIncludes |
Controls which property types are included by default. |
IgnoreAttribute |
Specifies which properties are ignored during generation. |
SkipAutoGeneratedPropertiesOnAdd |
Excludes database-generated properties from create DTOs. |
SkipAutoGeneratedPropertiesOnUpdate |
Excludes database-generated properties from update DTOs. |
SetAttributeType<T>() |
Specifies the attribute type used to control property inclusion. |
Property attributes
Property inclusion (or exclusion) can be customized by supplying your own attribute type:
.SetAttributeType<MyDtoPropertyAttribute>()
This allows different DTO variants to expose different subsets of properties while reusing the same entity model.
Build
After configuring all DTO variants, call Build() to create a TypeStore containing the DTOs.
var typeStore = new DtoBuilder()
// DTO configurations...
.Build();
The resulting TypeStore can then be used by EntityWebApi when resolving DTO types.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- GrumpTech.EntityWebApi.Core (>= 0.1.2)
- Microsoft.EntityFrameworkCore (>= 10.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.