Integrating Automapper with an MVC Result Filter

Published on May 4, 2015 by Jamie Munro


On a variety of actions inside your controllers you call the Automapper NuGet Package to convert from one model to another and you do not want to continue repeating this code each time.


Applying an MVC result filter to the action can execute the Automapper code after the action has been processed by the MVC framework and before the view is rendered.

Please note this is an excerpt from Chapter 9 of my ASP.NET MVC 5 with Bootstrap and Knockout.js book. In this chapter I provide a brief overview of the 5 different MVC filters and then over the next two chapters provide detail examples of each. The following post is leveraging the example of a Result Filter.

Read more >

Tags: ASP.NET | mvc | automapper | mvc5

Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

I hate typing more lines of code then I need to; especially something as simple as mapping a domain model to a view model.  Enter Automapper!

By performing a one-liner:
 Mapper.Map<Customer, CustomerViewItem>(customer);
I can quickly map my domain models to my view models.

I was recently reviewing an old article on CodeProject: that contains a quick and easy demo.  Inside this article, it discusses performance and it indicates that Automapper is 7 times slower than manual mapping.  This test was done on 100,000 records and I must say I was shocked.

My first thought is this requires more testing.  Especially since 100,000 records is a lot.  In most scenarios I would estimate my largest mapping might be 1,000, but even 1 would probably be a very regular use-case.  Let’s put it to the test…

Read more >

Tags: Optimization | ASP.NET | c# | automapper