views:

259

answers:

1

What do you think? How do you map between your domain and presentation model?

+3  A: 

Quoting part of an answer from another Automapper question:

If you have an object of one type and you want to populate the properties of an object of another type using properties from the first type, you have two choices:

  1. Manually write code to do such a mapping.
  2. Use a tool that will automatically handle this for you.

AutoMapper is an example of 2.

LINQ to Objects is an example of 1 - it just happens to be a bit less painful than writing vanila object-to-object mapping code.

In terms of pros and cons:

  • Automapper should significantly reduce the amount of code you have to write compared to LINQ as it uses conventions to determine default mappings. Using LINQ, these default mappings would have to be defined.

  • Using LINQ it will be necessary to define mappings in both directions - Automapper should be able to work this out automatically when conventions are used.

  • As with all third-party dll's, using Automapper will introduce another dependency and require a small learning curve (note there would be a learning curve for those developers who haven't used LINQ before as well).

Note, Automapper can be used in conjunction with LINQ (and LINQ2SQL) - yet another Automapper post which explains some of the finer points.

Bermo
what about dynamic proxy?
ktutnik