August 2017
Intermediate to advanced
330 pages
7h 26m
English
Any existing database would have many columns in tables. Sometimes, the web API response or request object does not need all properties in line with table columns.
We can write a trimmed down version of the Product class in the data access layer as the ProductDTO class in the Models folder. With many columns, manual mapping becomes difficult to maintain. The Product class should be transformed to ProductDTO and vice versa; this transformation can be eased using AutoMapper.
AutoMapper is a convention-based object-object mapper for .NET. Install this using NuGet.
First, let's create ProductDTO, a trimmed version of the Product class in the Models folder, as follows:
using System.ComponentModel.DataAnnotations; namespace AdvWorks.WebAPI.Models ...
Read now
Unlock full access