What’s Automapper for?
How will it help me with my domain and controller layers (asp.net mvc)?
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.
Maybe an example will help here…
Let’s say you have a nicely-normalized database schema like this:
And let’s say you’re using a nice O/R mapper that hands you back a well-organized domain model:
Now you’re given a requirement to display everything that’s been ordered in the last month. You want to bind this to a flat grid, so you dutifully write a flat class to bind:
That was pretty painless so far, but what now? How do we turn a bunch of
OrderDetails into a bunch ofOrderDetailDtos for data binding?You might put a constructor on
OrderDtothat takes anOrderDetail, and write a big mess of mapping code. Or you might have a static conversion class somewhere. Or, you could use AutoMapper, and write this instead:There. We’ve just taken what would otherwise have been a disgusting mess of pointless mapping code and reduced it into three lines (really just two for the actual mapping).
Does that help explain the purpose?