Thursday, November 22, 2018

Automapper

Automapper used to copy data from one object to another.

When we have to copy properties from viewmodel to model than same properties needed in model also in that case Autompper come in light.

The real problem arises when we have 25-30 fields in a record from the database and we need to repeat this same binding code all over in the project.

AutoMapper not only reduces the effort but it also limits the execution time that has been taken by such a large number of lines to execute.

Life without Automapper

 class MainClass
    {
        private void CopyData()
        {
            Person objPerson = new Person();
            Student objStudent = new Student();

            objPerson.FirstName = "Khaleek";
            objPerson.LastName = "Ahmad";

            objStudent.FirstName = objPerson.FirstName;
            objStudent.LastName = objPerson.LastName;
        }
    }

    class Student
    {
        public String FirstName  { get; set; }
        public String LastName { get; set; }
    }

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

Life with Automapper



No comments:

Followers

Link