What is the point of AutoMapper? Could someone give me a really simple example?
I have watched the video on it, but it is just not clicking.
Sam
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Typically AutoMapper is great at mapping between data entities and business models. E.g., lets say for instance, I have a data domain type, call it
PersonEntity, and it has an array of properties:FirstName,Surname,Genderetc. I don’t want to expose my data domain type through to the consuming application, so I can define business domain types, e.g.Person, now thePersontype can contain additional business logic, such asGetRelatedPersons, etc, which may not be functionality tied to your data domain. In this case, I have two types,PersonEntityandPersonwhich at some point I will have to write boilerplate code to copy the properties from one to the other. I could do this a variety of ways, I could:1.Copy Constructor:
2.Generalised Mapping Method:
3.Implicit/Explicit Conversion:
But what AutoMapper allows you to do, is easily create a mapping process between those two types. So in its simiplist form, I could:
By using a convention-first approach, the AutoMapper framework will translate matching properties from one instance to the next. It also allows you to customise how the types are mapped if you want more fine grained control.
Hope that helps.