Open Closed

AutoMapperMappingException: Missing type map configuration or unsupported mapping. #814


User avatar
0
Gary created
  • ABP Framework version: 4.1.1
  • UI type: MVC
  • DB provider: EF Core
  • **Tiered (MVC)
  • Exception message and stack trace:AutoMapperMappingException: Missing type map configuration or unsupported mapping.
  • Steps to reproduce the issue: On create I want to move the data in the Prospectus table to the Student table. The Prospectus table is a subset of the Student table.

In the MapperProfile I created the map `//map the prospectus to the student

        CreateMap<ProspectusCreateDto, Student>().IgnoreFullAuditedObjectProperties().Ignore(x =>      x.ExtraProperties).Ignore(x => x.ConcurrencyStamp).Ignore(x => x.Id).Ignore(x => x.TenantId);`
        
        

In my ProspectusAppService class I modified the Create method

      public virtual async Task<ProspectusDto> CreateAsync(ProspectusCreateDto input)
        {
            var prospectus = ObjectMapper.Map<ProspectusCreateDto, Prospectus>(input);
            prospectus.TenantId = CurrentTenant.Id;

            //get the Position role from the position Id
            var SelectedPosition = _positionRepository.AsQueryable()
                    .Where(p => p.Id == prospectus.PositionId)
                    .Select(p => new { Role = p.Role, Id = p.Id }).FirstOrDefault();

            if (SelectedPosition.Role == "Student") //student
            {
                var student = ObjectMapper.Map<ProspectusCreateDto, Student>(input);
                student.TenantId = CurrentTenant.Id;

                //save it to the student table
                await _studentRepository.InsertAsync(student, autoSave: true);

                //delete it from the prospectus table if it exists
                if (prospectus.Id != default(Guid))
                {
                    await DeleteAsync(prospectus.Id);
                }

            }
            else
            {
                prospectus = await _prospectusRepository.InsertAsync(prospectus, autoSave: true);
            }
            return ObjectMapper.Map<Prospectus, ProspectusDto>(prospectus);
        }

At var student = ObjectMapper.Map<ProspectusCreateDto, Student>(input);

I get


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the full code of ProspectusCreateDto and Student class?

    Have you tried the Automapper without abp?

  • User Avatar
    0
    Gary created

    Thankyou, for your help. I have found out the error, your post gave me the idea, a field in the Prospectus was a different type to the one in Students :-)

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11