0
votes

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,

  1. Model

    public class Model
    {
        public string ResultType { get; set; }
    }
    
  2. ViewModel

    public class ViewModel : Screen
    {
        private string _resultType;
    
        public string ResultType
        {
            get { return _resultType; }
            set
            {
                _resultType = value;
                NotifyOfPropertyChange(() => ResultType);
            }
        }
    }
    
  3. 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

1
Please show your mapping.Rabban

1 Answers

1
votes

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