Automapper in ASP.NET MVC - An Introduction

AutoMapper is an external component that helps in creating a mapping between a source and destination model types. Once the mapping is created then the source model object can be converted to a destination model object with ease and with less code.

Let create a simple class named Student and another class named Person and then we try to map properties of these two classes with our traditional method and then using new Automapper.

class Student
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Subject { get; set; }
// Loaded with some data
Student stud = new Student();
stud.FirstName = "Bob";
stud.LastName = "Smith";
stud.Subject = "Maths";

class Person
        public string FirstName { get; set; }
        public string LastName { get; set; }

Normally we used to have a mapping code as shown below:

Person person=new Person();


But if we want to resue this mapping code then there is a solution to this issue as "AutoMapper".

“Automapper” sits in between both the objects like a bridge and maps the property data of both objects. It can be installed from Nuget.

Create the Map:

Mapper.CreateMap<Student, Person>(); 

Use the Map so that objects can communicate.
Person person =  Mapper.Map<Student, Person>(stud);

Here the mapping happens automatically based on the property names of both classes. In case of the classes having different property names we need to use "ForMember" function to indicate tha mapping as shown below:

Mapper.CreateMap<Student, Person>()
.ForMember(person => person.FName , opt => opt.MapFrom(stud => stud.FirstName))
.ForMember(person => person.LName , opt => opt.MapFrom(stud => stud.LastName));

Posted: Apr 25, 2018,
Categories: .NET Platform,
Comments: 0,
Author: Urish Arora
Rate this article:

Urish AroraUrish Arora

Other posts by Urish Arora

, Contact author

Please login or register to post comments.




Subscribe to our blog

«November 2019»

  • Featured Posts
  • Recent Posts
  • Recent Comments
Dynamics365Authority is a community platform for Professionals and Students to contribute or share their knowledge and skills on Microsoft Dynamics 365 Technologies. Our primary goal is to invite professionals on Dynamics 365 technology across the world to contribute & share their knowledge and skills through their blogs so that we can help other developers.
Stay updated with Dynamics 365 technology. Improve skills and knowledge from our blogs, articles and code snippets. Learn it. Follow professionals and learn from them.
Unified Service Desk Book(Online Edition) 


Stay connected with us on our social media channels for latest articles, blogs posts etc.  We will keep updating regularly on our social media platform and web platform.


Follow us on Facebook



View all our tweets



Join us now



View our blogs



Latest Blog

Posted: Jun 20, 2019

Overview - Appendix (Unified Service Desk)

This blog is about Appendix

Read more
Posted: Jun 20, 2019

Overview - Troubleshoot and Debug (Unified Service Desk)

This blog is about Troubleshoot and Debug in Unified Service Desk

Read more
Posted: Jun 20, 2019

Overview - Performance (Unified Service Desk)

This blog is about the Performance in Unified Service Desk

Read more


Dynamics 365 - Search the library for "Dynamics 365"

  What's New in Dynamics 365

  Dynamics 365 Documentation


  Sign-up for 30 days trial



Recent comments


Nice blog. Very helpful to get all references to white papers at one place.

Previous Next

About Us

Here comes the Dynamics 365 Authority - Great technical blog posts are hidden gems. They are hard to find simply because not enough of us write them in the first place. Yet technical blogging is one of the best things we can do not only for ourselves, but also as members of the wider community of developers.

Dynamics 365 Authority leverages this platform to help developers and users to move from traditional paper-based process to modern digital business process. helps your business grow, evolve and transform. is your Digital Transformation Partner

Recent Posts

Overview - Appendix (Unified Service Desk)

This blog is about Appendix
  • 238
  • Article rating: 5.0

Overview - Troubleshoot and Debug (Unified Service Desk)

This blog is about Troubleshoot and Debug in Unified Service Desk
  • 359
  • Article rating: 5.0

Get in touch

Follow Us


Tag cloud: with Urish Arora;; Sales; Leading community site on MS Dynamics 365; Dynamics 365 Authority; Service;Top CRM Blogs; Urish Arora - Australia's leading expert on Digital Transformation;  Digital Transformation; Field Service;Top Articles on MS Dynamics CRM Relationship Insights; Office 365 Security Compliance; Project Service; Microsoft Dynamics 365 for Sales; Relevance Search; Goal Metrics; Activities and Case; Sales Literature;Knowledge Management;

Terms Of UsePrivacy StatementCopyright 2019 by Dynamics365Authority
Back To Top