Domain model:
public class Test
{
public int Id { get; set; }
}
View model:
public class TestViewModel
{
public int Id { get; set; }
}
Global.asax:
AutoMapper.Initialize();
AutoMapper:
public static class AutoMapper
{
public static void Initialize()
{
CreateModelsToViewModels();
CreateViewModelsToModels();
}
private static void CreateModelsToViewModels()
{
Mapper.Initialize(x => x.CreateMap<Test, TestViewModel>().ReverseMap());
Mapper.AssertConfigurationIsValid();
}
private static void CreateViewModelsToModels()
{
}
}
Configuration is valid.
public ActionResult Index(string category)
{
Test t = _Context.test.First(x => x.Id == 1);
var test = Mapper.Map<Test, TestViewModel>(t); //error here
}
Only data is one row with an Id of 1. Even this simple test keeps throwing me the error Missing type map configuration or unsupported mapping.
What could be the problem?
Edit: Changed Mapper.Initialize(x => x.CreateMap<Test, TestViewModel>().ReverseMap()); to Mapper.Initialize(x => x.CreateMap<Test, TestViewModel>()); and still same error
ReverseMap()Creates a map both ways. so I deleted my wrong answer