DTO is used to define the input and output data structure of interfaces. When interacting with databases, type conversion is required. We use Mapster for conversion between entity classes and DTOs. DTO content is generated based on entity classes, which is a prerequisite.
This document explains how to generate DTO classes and DTO generation rules.
Based on entity classes, the following DTO types are generated:
| DTO | Purpose |
|---|---|
| ItemDto | List elements |
| DetailDto | Entity details |
| FilterDto | Filter condition model |
| AddDto | Add model |
| UpdateDto | Update model |
When generating DTOs, DTO information is cached. After generation completes, the cache is cleared.
See the DtoCodeGenerate class for specific implementation details.
DTOs globally ignore the following properties (temporary limitation):
[JsonIgnore] attributeJsonDocument or byte[]Future updates will handle these properties.
Tip
Since EntityFrameworkCore.Design is used to obtain entity information, properties not recognized as database-mapped properties will not be included in Add/Update DTO generation.
For each DTO type, properties are filtered and processed based on the specific usage scenario.
Add model generation content:
set method.required keyword restrictions for better instance creation.List elements do not include the following properties:
Detail DTO does not include the following properties:
JsonDocument and byte[]FilterDto generation content:
Update model generation is the same as add model, but all properties are nullable by default.
Nullable properties mean that if a field is null, the update ignores that field, implementing partial updates.