I am developing an ASP.NET MVC3 application in C# and Razor. The architecture of the application is divided in Data Access Layer (EF classes + Repository), Service Layer, Controller, ViewModels and View.
In the controller I obtain from my Service Layer:
-
From the method
Product GetProduct(id), aProductobject which contains all the information about a product to be displayed in the View -
From the method
Filter GetFilter()aFilterobject that contains all the info that are used for the search filter such list of products to be chosen from a dropdownlist, etc…
Now if I use AutoMapper how can I map these information in a SelectProductViewModel class?
public class SelectProductViewModel
{
public Product ProductToDisplay { get; set; }
public Filter SearchFilter { get; set; }
}
AutoMapper is used to map between a single source type to a single destination type. You cannot use it in this context. So it could be as simple as: