Because AutoMapper uses Reflection perfomance will always be lower than doing it your self. I'm using Subsonic for my DAL and really the DAL has no knowledge of the View. I cretae a Partial class to add the extra functionality.
Code:
namespace Lib.Data
{
public partial class Product : Lib.Data.DAL.Product
{
public ProductModel ToDataModel()
{
var returnData = new ProductModel();
returnData.Name = this.Name;
return returnData;
}
}
}
Now that will work with SubSonic or Entity framework or ideally any ORM tool. I can now do the following in my service layer.
Code:
var curProduct = new Lib.Data.Product(); //Obv have the fetch one
//Return as data model
curProduct.ToDataModel();
Now, i'm open to reasons why this is good or bad and interested to share your thoughts.