title: AutoMapping entities to models through an action filter attribute?
body: <p>In <strong><a href="http://lostechies.com/jimmybogard/2009/06/30/how-we-do-mvc-view-models/" rel="nofollow noreferrer">this article</a></strong>, <a href="https://stackoverflow.com/users/58508/jimmy-bogard">Jimmy Bogard</a> goes on to explain some of the best-practices he endorses when doing MVC.</p>
  
  <p>The article in general is pretty good and I've found his advice in general (in other blog posts) to be pretty solid. However, he suggests using an attribute to map entities to models.</p>
  
  <p>How is this</p>
  
  <pre><code>[AutoMap(typeof(Product), typeof(ShowProduct))]
  public ActionResult Details(int id)
  {
      var product = _productRepository.GetById(id);
      return View(product);
  }
  </code></pre>
  
  <p>Any better than this (which in my opinion is way more declarative as to the actual intent of the piece of code</p>
  
  <pre><code>public ActionResult Details(int id)
  {
      var product = _productRepository.GetById(id);
      var model = Mapper.Map&lt;Product, ShowProduct&gt;(product);
      return View(model);
  }
  </code></pre>
  
  <p>Besides that one point, there seem to be scenarios where this is rather impractical, such as action methods returning different models based on input, or even simpler scenarios such as this:</p>
  
  <pre><code>    [HttpGet]
      public ActionResult Index()
      {
          return List();
      }
  
      public ActionResult Until(long id) // "id" is the timestamp
      {
          return List(id);
      }
  
      [NonAction]
      internal ActionResult List(long? timestamp = null, int count = 8)
      {
          IEnumerable&lt;Post&gt; posts = postService.GetLatest(timestamp, count);
          PostListModel model = mapper.Map&lt;IEnumerable&lt;Post&gt;, PostListModel&gt;(posts);
          return ContextView("List", model);
      }
  </code></pre>
  
  <p>Is this actually a good practice, or just unjustified, an unwarranted obfuscation of code that was already pretty simple to begin with?</p>
  
  <p>I ask out of ignorance, not personally attacking someone I regard as an awesome blogger, besides I love AutoMapper already.</p>