Flattening Example
ℹ️ Description: AutoMapper automatically flattens nested properties (e.g., Category.Name -> CategoryName).
Product Result
| Property | Value |
|---|---|
| Id | 1 |
| Name | Laptop |
| Description | High-performance laptop |
| Price Formatted | $1,299.99 |
| Category Name Flattened | Electronics |
| Category Description Flattened | Electronic devices and accessories |
| In Stock | Yes |
| Availability Status Resolver | In Stock |
🔍 Flattening Explained
AutoMapper automatically flattens nested properties:
// Source object structure
Product {
Category {
Name = "Electronics"
Description = "Electronic devices"
}
}
// Destination DTO (flattened)
ProductDTO {
CategoryName = "Electronics" // Automatically mapped from Category.Name
CategoryDescription = "Electronic devices" // From Category.Description
}
How it works: AutoMapper looks for properties that match the pattern NestedObjectProperty and automatically maps from NestedObject.Property.