Automapper missing type map configuration or unsupported mapping - Error

前端 未结 12 1395
旧时难觅i
旧时难觅i 2020-11-27 16:25

Entity Model

public partial class Categoies
{
    public Categoies()
    {
        this.Posts = new HashSet();
    }

    public int Id { get; se         


        
相关标签:
12条回答
  • 2020-11-27 16:46

    I found the solution, Thanks all for reply.

    category = (Categoies)AutoMapper.Mapper.Map(viewModel, category, typeof(CategoriesViewModel), typeof(Categoies));
    

    But, I have already dont know the reason. I cant understand fully.

    0 讨论(0)
  • 2020-11-27 16:49

    Check your Global.asax.cs file and be sure that this line be there

     AutoMapperConfig.Configure();
    
    0 讨论(0)
  • 2020-11-27 16:49

    Upgrade Automapper to version 6.2.2. It helped me

    0 讨论(0)
  • 2020-11-27 16:57

    I was trying to map an IEnumerable to an object. This is way I got this error. Maybe it helps.

    0 讨论(0)
  • 2020-11-27 16:57

    I created a new AutomapperProfile class. It extends Profile. We have over 100 projects in our solution. Many projects have an AutomapperProfile class, but this one was new to this existing project. However, I did find what I had to do to fix this issue for us. There is a Binding project. Within the Initialization there is this code:

    var mappingConfig = new List<Action<IConfiguration>>();
    
    // Initialize the Automapper Configuration for all Known Assemblies
    mappingConfig.AddRange( new List<Action<IConfiguration>>
    {
       ConfigureProfilesInAssemblyOfType<Application.Administration.AutomapperProfile>,
       //...
    

    I had to add ConfigureProfilesInAssemblyOfType<MyNewNamespace.AutomapperProfile>

    Note that ConfigureProfilesInAssemblyOfType looks like this:

        private static void ConfigureProfilesInAssemblyOfType<T>( IConfiguration configuration )
        {
            var log = LogProvider.Get( typeof (AutomapperConfiguration) );
    
            // The Automapper Profile Type
            var automapperProfileType = typeof (Profile);
    
            // The Assembly containing the type
            var assembly = typeof (T).Assembly;
            log.Debug( "Scanning " + assembly.FullName );
    
            // Configure any Profile classes found in the assembly containing the type.
            assembly.GetTypes()
                .Where( automapperProfileType.IsAssignableFrom ).ToList()
                .ForEach( x =>
                {
                    log.Debug( "Adding Profile '" + x.FullName + "'" );
                    configuration.AddProfile( Activator.CreateInstance( x ) as Profile );
                } );
        }
    

    Best regards, -Jeff

    0 讨论(0)
  • 2020-11-27 17:01

    In my case, I had created the map, but was missing the ReverseMap function. Adding it got rid of the error.

          private static void RegisterServices(ContainerBuilder bldr)
          {
             var config = new MapperConfiguration(cfg =>
             {
                cfg.AddProfile(new CampMappingProfile());
             });
             ...
           }
    
    
          public CampMappingProfile()
          {
             CreateMap<Talk, TalkModel>().ReverseMap();
             ...
          }
    
    0 讨论(0)
提交回复
热议问题