It’s time for another episode of the Mvc Screencast! I hope you’ve been able to check out the first eight episodes to date. If so, feel free to leave a comment here and let me know what you think. Don’t be shy about tweeting or sharing this series, either. I’d appreciate it if you did!

AutoMapper

In this episode, I talk about Big M Models, Domain Models, View Models, object-to-object mapping, and finally AutoMapper, an OSS tool created by Jimmy Bogard with the goal of making object-to-object mapping simple, conventional and configurable. I’ll also demonstrate how you can quickly integrate AutoMapper into an MVC application, and use it to map from Domain objects to ViewModel objects.

If you want to learn more about AutoMapper, check out automapper.codeplex.com. You can also download or fork the source on GitHub at github.com/jbogard/automapper.

Click on the embedded video below (~17 minutes), click here to view it on Channel 9, or if you want to view the video on your shiny, new WIndows Phone 7, click here to download a mobile-ready version.

I’d love to hear your thoughts, questions or suggestions below. Thanks for watching and sharing!

Tagged with:
 
  • Ignacio Fuentes

    I know it’s been a while since you posted this but Im still somewhat confused about Automapper. It really does work pretty well to generate a viewmodel from a domain model but doesnt really work well for the opposite (i have had many problems with it at least).. Jimmy Bogard actually discourages this practice http://lostechies.com/jimmybogard/2009/09/18/the-case-for-two-way-mapping-in-automapper/ …. although I dont really understand his approach on solving it… what do you feel on this issue?

  • Ignacio Fuentes

    Reading more and more into it, people very frequently will have problems that dont seem to have a clean solution…. http://stackoverflow.com/questions/4587536/design-pattern-for-mapping-dtos-containing-child-collections-back-to-domain-model 

  • http://www.userinexperience.com Brandon Satrom

    I can understand where Jimmy is coming from on this issue. In a perfect world, it’s probably best to use a Command pattern varation and/or CQ(R)S in your architectures, which obviates the need for two-way mappings. However, I don’t think Command/CQRS is ALWAYS appropriate, especially with simplier applications. One could argue that perhaps AutoMapper isn’t appropriate in those cases, but I’m not sure I agree since there are many who advocate ALWAYS using DTOs in MVC applications, regardless of size.

    So where I stand is this: If complexity warrants, use Command with AutoMapper. Otherwise, use AutoMapper with one of the two-way workarounds or handle the mappings by hand.

    Hope that helps!

Switch to our mobile site