I\'ve got some problems using EF with AutoMapper. =/
for example :
I\'ve got 2 related entities ( Customers and Orders ) and they\'re DTO classes :
Now, with new version of AutoMapper, the recommended way is using Queryable-Extensions:
When using an ORM such as NHibernate or Entity Framework with AutoMapper's standard Mapper.Map functions, you may notice that the ORM will query all the fields of all the objects within a graph when AutoMapper is attempting to map the results to a destination type.
If your ORM exposes IQueryables, you can use AutoMapper's QueryableExtensions helper methods to address this key pain.
The .ProjectTo() will tell AutoMapper's mapping engine to emit a select clause to the IQueryable that will inform entity framework that it only needs to query the Name column of the Item table, same as if you manually projected your IQueryable to an OrderLineDTO with a Select clause.
Create a mapping:
Mapper.CreateMap();
And project query to dto:
var customerDto =
session.Query().Where(customer => customer.Id == id)
.Project().To()
.Single();