Mapping Complex type to Primitive Type using AutoMapper in C#



Mapping Complex type to Primitive Type using AutoMapper in C#

In this article, I am going to discuss how to map Complex type to Primitive Type using AutoMapper in C# with examples. Please read our previous article where we discussed Automapper Complex Mapping with some examples. At the end of this article, you will understand and when and how to map complex type to primitive type using auto mapper.


When to map Complex type to Primitive Type using AutoMapper in C#?

When one class contains primitive types or you can say the simple types and the other class contains complex type involved in the mapping then in such scenarios we need to Map the Complex Type to the Primitive Types. Let us understand how to map Complex type to Primitive Type using AutoMapper in C# with an example. Here in this demo, we are going to use the following three classes (Employee, EmployeeDTO and Address).


    public class Employee

    {

        public string Name { get; set; }

        public int Salary { get; set; }

        public string Department { get; set; }

        public Address address { get; set; }

    }

    public class EmployeeDTO

    {

        public string Name { get; set; }

        public int Salary { get; set; }

        public string Department { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public string Country { get; set; }

    }

    public class Address

    {

        public string City { get; set; }

        public string State { get; set; }

        public string Country { get; set; }

    }

0 Comment's

Comment Form

Submit Comment