I have an entity called Incident
and a DTO called IncidentDTO
. For now, IncidentDTO
simply looks like this:
public class IncidentDTO : Incident
{
// empty until I can get AutoMapper working correctly
}
I'm trying to pull a list of all the Incidents
in the database and convert them to DTOs using this code:
Mapper.CreateMap<Incident, IncidentDTO>();
using (var session = SessionFactory.OpenSession())
{
var incidents = session.Linq<Incident>();
var incidentDTOs = Mapper.Map(incidents, new List<IncidentDTO>());
}
This code works fine, except when I use NHProf to look at the SQL statements being generated, I get this:
SELECT ... FROM [Incident] this_
SELECT ... FROM [Incident] this_
The two SELECT statements are exactly identical. Why does AutoMapper generate two identical SELECT statements, and how do I prevent it from doing this?