This article demonstrates what Automapper is and how we can integrate Automapper to our ASP.NET Core application.
Download Source code from the given GitHub URL.
Tools Used for development
- Visual Studio 2019
What is AutoMapper?
AutoMapper in C# is a mapper between two objects. That is, AutoMapper is an object-object mapper. It maps the properties of two different objects by transforming the input object of one type to the output object of another type.
Why do we need AutoMapper in C#?
Let’s understand why we need automapper in C# with an example. Let’s say we have two classes such as Employee and EmployeeDTO as shown in the below image.
Step by step walkthroughs
Will see step by step how we can integrate Automapper to a project.
Step 1
Add the AutoMapper.Extensions.Microsoft.DependencyInjection Package to your solution via NuGet.
Step 2
Create two files as Customer.cs and CustomerModel.cs and add class Customer and CustomerModel.
- public class Customer {
- public int CustomerId { get; set; }
- public string CompanyName { get; set; }
- public string FirstName { get; set; }
- public string MiddleName { get; set; }
- public string LastName { get; set; }
- public string Address { get; set; }
- public string Phone { get; set; }
- public string Country { get; set; }
- public string City { get; set; }
- public string Pincode { get; set; }
- }
- public class CustomerModel {
- public int CustomerId { get; set; }
- public string FullName { get; set; }
- public string Phone { get; set; }
- public string Country { get; set; }
- public string City { get; set; }
- public string Pincode { get; set; }
- }

Matias LagatPosted Aug 10, 2021, 3:18 AM
Thanks.. I have a question. Can I create another profile e.g SalesProfile then add this as Configuration in the Startup.cs like the CustomerProfile? Do you have any example on this? Thanks a lot.
Burak DoganPosted Mar 22, 2021, 8:43 AM
Thank you so much.