Automapper Mapping Exception with Model and private Properties
I am using AutoMapper to map two objects. ViewModel and Model, where ViewModel Implements InotifyPropertyChanged. How can i map Model to ViewModel. Below is my scenario,
Model
public class Model
{
public string ResultType { get; set; }
}
ViewModel
public class ViewModel : Screen
{
private string _resultType;
public string ResultType
{
get { return _resultType; }
set
{
_resultType = value;
NotifyOfPropertyChange(() => ResultType);
}
}
}
Create Map implementation
mapper.CreateMap<Model, ViewModel>();
mapper.CreateMap<ViewModel, Model>();
mapper.AssertConfigurationIsValid();
var test1 = new Model() {ResultType = "Test Result"};
var s1 = mapper.Map<ViewModel>(test1);
I get AutoMapper Mapping Exception when i call mapper.Map.
Missing type map configuration or unsupported mapping. Mapping types: Model-> ViewModel Support.Model -> Support.ViewModel
Like mentioned, you aren't actually showing any mapping code. Based on what you've provided, do something like this:
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<Model, ViewModel>();
});
Here's a working example: https://dotnetfiddle.net/YnZ1nw
链接地址: http://www.djcxy.com/p/37418.html