I'm considering to use AutoMapper in the upcoming project and trying to find possible "bottlenecks". At the moment the most complex case i can imagine is the following: A domain class which is represented by 3 (for example) tables in the database (my data access layer is LINQ to SQL). To build an instance of the class i need to perform 3 queries:
- Select by ID from table A (1 row, goes directly to
Class
properties) - Select by ID from table B (0..1 rows, goes to optional
Class.Code
property) - Select by ID from table C (0..N rows, goes to
Class.Parameters
collection)
And i'm not sure how to configure the mapping. Here are the options i considered:
- Perform 3 queries and map
Tuple<A,B,C>
->Class
- Combine queries 1 and 2 using outer join (more effective). But what do i do with anonymous type?
- Inject datacontext into the mapping, define
A
->Class
mapping and let the type converters do the job?
None looks like a win. What would you suggest?
Edit: Well, such complex cases is quite rare (10-20%) and i can do them manually and the rest 80-90% with AutoMapper just fine. But i'd like to know if AutoMapper is not designed for such strategies or i'm missing something important.