automapper in Csharp with example - Tutorial

For Consultation : +91 9887575540

Stay Connected :

AutoMapper in C#

AutoMapper is utility package provided by the Microsoft net framework. Automapper provides mapping between one class object to another class object. In simple words assigning properties values of one class into another class is called automapping. You can download automapper package from nu-get package manager or package manager console.

For Example If I created two classes Person and employee as below

Now I want to mapping(Assigning person properties values into employee properties) between them , Traditional approach to do this

This code will work fine but the cons of this approach to write lots of code.

Now see that how It can be done using automapper.

To implement this we need to install automapper utility through Microsoft Nu-Get

RightClick on Project->Select Manage NuGet Packages->Write automapper in search box ->After searching finishes ,select and install automapper.


After this process AutoMapper package will be added in references folder.


Now I am going to write code again using automapper.

Employee classes properties are automatically mapper because of same property name are assigned to person class but if any case when source and destination classes properties are different then we have to do properties mapping also.

Like classes structure are

Then write mapping like this.

Complete Code

 Latest Version of AutoMapper example code


Select your currency