top of page

Easy Guide to AutoMapper (Simple Class Converter) - C# & .NET

While you are creating numerous classes during development, there are numerous cases where you have to convert from one to another classes. For example, you may want to convert classes generated by Entity Framework to a class for use with Web API or client application. Many cases you may include same property names. During this process, you may be writing extra codes to convert from one to another class. AutoMapper will help you minimize number of repetitive lines of conversion codes you write.

AutoMapper Site:

 

Installation Instructions


In Visual Studio's Package Manager, you can install it by entering the following command. Or you can install from NuGet.

Install-Package AutoMapper
 

Use Case


You will need a mapper configuration first (shown as example below). Create a new mapper configuration with the source and destination class. The example below is to convert from Order to OrderDto class.


By default, it will only map the properties with the same names. If you want to map different property names, use Linq to map names as example shown below:


The code above will map OrderTitle in the source class (Order) to OrderName in the destination class (OrderDto).

Comments


pngegg (11)_result.webp

<Raank:랑크 /> 구독 하기 : Subscribe

감사합니다! : Thanks for submitting!

bottom of page