I am using EF Code First and defined a number of POCOs. On the other hand, There are some ViewModel classes defined for each of which. Up to here, there are two projects; Model and MVC. Moreover, there is another project containing UnitOfWork and Repository Pattern(a generic repository class).
In the UnitOfWork a number of fields and properties written. Here is an example:
public GenericRepository<ActionProvider> ActionProviderRepository
{
get
{
if (this.actionProviderRepository == null)
{
this.actionProviderRepository = new GenericRepository<ActionProvider>(context);
}
return actionProviderRepository;
}
}
The type of this property is that of ActionProvider class defined in the Model project.
But my problem; I need to Map each of the ViewModel to the POCO classes. After surfing the web, I've come to apply AutoMapper. So the following is what I have done in the UserController class:
public class UserController : Controller
{
private UnitOfWork unitOfWork = new UnitOfWork();
private User _UserModel = new User();
private VM_User _VM_User = new VM_User();
//
// GET: /User/
public ViewResult Index()
{
_VM_User = Mapper.Map<MAHAL_E_MA_Model.POCO.User, VM_User>(_UserModel);
return View(unitOfWork.UserRepository.Get(orderBy: us => us.OrderByDescending(u => u.ID)).OfType<User>().ToList());
}
}
And the error is:
Missing type map configuration or unsupported mapping.
I have tried through these links and some other ones but did't work for me! This one
Any help would be kindly appreciated..