object mapping
Copying data from one type to another across a boundary, such as from a database entity to an API response record.
In more detail
Writing it by hand makes every field that crosses the boundary visible and easy to test. Keep business decisions out of mappers.
Example
public static ProductResponse ToResponse(this Product p) => new(p.Id, p.Name, p.Price);Related terms
- DTO — A plain object whose only job is to carry data across a boundary, such as the body of an API request or response.
- entity — A thing in an application's domain with its own identity, such as a user, account or product, usually stored in a database.
- Mapperly — An open-source .NET library that generates object-mapping code at compile time from a partial class marked [Mapper].
- AutoMapper — A popular .NET library that maps objects by naming convention at run time, which moved to a commercial licence in 2025.
Taught in
- Manual Object Mapping — Modern .NET Core, C# & Enterprise Microservices
- Source-Generated Mapping with Mapperly — Modern .NET Core, C# & Enterprise Microservices