Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This file generates an error in VS2015 #1

Open
andytherunner opened this issue Jan 9, 2017 · 2 comments
Open

This file generates an error in VS2015 #1

andytherunner opened this issue Jan 9, 2017 · 2 comments

Comments

@andytherunner
Copy link

Error CS0117 'Mapper' does not contain a definition for 'CreateMap' Store.Web

MVCArchitecture-master\mvcarchitecture-master\Store.Web\Mappings\ViewModelToDomainMappingProfile.cs 21 Active

@suresh-kaushik
Copy link

suresh-kaushik commented May 18, 2017

Update your Nuget packages, except the Automapper. Keep the Automapper to 4.2.0, since the CreateMap method was depricated and eventually removed in v5.0.
It would give you this error otherwise:

AutoMapper.Mapper does not contain definition for CreateMap

Automapper v4.2.0 will resolve your particular issue.

@alfmoh
Copy link

alfmoh commented May 28, 2017

You can update alright but create your mappings in the constructor of the DomainToViewModelMappingProfile and ViewModelToDomainMappingProfile. So they end up looking like this,

public class DomainToViewModelMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "DomainToViewModelMappings"; }
        }

        public DomainToViewModelMappingProfile()
        {
            CreateMap<Category, CategoryViewModel>();
            CreateMap<Gadget, GadgetViewModel>();
        }
    }
public class ViewModelToDomainMappingProfile : Profile
    {
        public override string ProfileName { get { return "ViewModelToDomainMappings"; } }

        public ViewModelToDomainMappingProfile()
        {
            CreateMap<GadgetFormViewModel, Gadget>()
                .ForMember(g => g.Name, map => map.MapFrom(vm => vm.GadgetTitle))
                .ForMember(g => g.Description, map => map.MapFrom(vm => vm.GadgetDescription))
                .ForMember(g => g.Price, map => map.MapFrom(vm => vm.GadgetPrice))
                .ForMember(g => g.Image, map => map.MapFrom(vm => vm.File.FileName))
                .ForMember(g => g.CategoryID, map => map.MapFrom(vm => vm.GadgetCategory));
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants