I've created the following extension method:
public static T Map<TEntity,T>(this TEntity entity) where TEntity : IEntity
{
return Mapper.Map<TEntity, T>(entity);
}
This allows the following:
Db.ExchangeSets.FirstOrDefault().Map<ExchangeSet, ExchangeSetSimpleViewModel>()
However i'm wondering if there is anyway I can modify the extension method so i can call a shorted version as follows:
Db.ExchangeSets.FirstOrDefault().Map<ExchangeSetSimpleViewModel>()
Please Note:
Whether or not automapper should be used like this is not in the scope of the question, it's more a fact finding mission.
Update
For those of you playing at home, with the help of Scott's comment I managed to find an additional solution for the above function at Generic extension method for automapper.
public static T Map<T>(this IEntity entity)
{
return (T)Mapper.Map(entity, entity.GetType(), typeof(T));
}