AutoMapper/AutoMapper — Issue #175: There is a problem with mapping Guids
Author: dagostinelli
Created: 2012-02-28 01:57:21+00:00
State: open

This works:

DataSet ds = SqlHelper.ExecuteDataset(_connectionString, "dbo.GetOrders", orderBy, orderByDirection)
return ds.Tables[0]
.AsEnumerable()
.Select(x => Guid.Parse(x[0].ToString()))
.ToList();

This doesn't:

return SqlHelper.ExecuteReader(_connectionString, "dbo.GetOrders", orderBy, orderByDirection)
.AutoMap();

Where .AutoMap() is an extension method as follows:

public static List AutoMap(this IDataReader reader)
{
Mapper.CreateMap>();
return Mapper.Map>(reader)
.ToList();
}

The exception is:

System.Data.IDataReader -> System.Collections.Generic.IEnumerable`1[[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

Destination path:
IEnumerable`1

Source value:
System.Data.SqlClient.SqlDataReader

The exception happens because Automapper doesn't like an IDataReader that returns only a single list of value-types.

Please fix. I love your library otherwise.