So I have a 7 ViewModels that reference 3 domain models, I used automapper to map the Models to the ViewModels, That worked great, now I want to populate the ViewModel from data stored in the database and I’m running into alot of problems.
Here is my Automapper.Configure()
protected override void Configure()
{
//Configure dynamically at save time.
CreateMap<Step0ViewModel,Preparer>();
CreateMap<Step1ViewModel, BusinessInformation>();
CreateMap<Step2ViewModel, dr405>();
CreateMap<Step3ViewModel, dr405>();
CreateMap<Step4ViewModel, dr405>();
CreateMap<Step5ViewModel, dr405>();
CreateMap<Step6ViewModel, dr405>();
}
How do I tell the application, “When I load from DBContext, move the entity into the ViewModel automatically”, It seems like with Automapper you can load an entity from a ViewModel, but not the reverse.
Automapper can do the reverse, you just have to create the map for it:
As for loading mapping automatically at load time, I’m not aware of this functionality but it can be setup with a mapping helper to your linq query pretty easy:
Then in your query: