Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Custom entity DTO mapping error #2061


User avatar
0
exlnt created

The AutoMap function is failing and throwing an error on my edit DTO to entity mapping.

You can see my "company" entity and the "EditCompanyDto" here: [https://drive.google.com/open?id=0BzbrPy41GhA4VGFLUThtVDJMblE])

When my edit modal is opened and the query is executed and then results are mapped to "EditCompanyDto" I get the below error message.

<span style="color:#FF0000">Mapping types: List1 -> EditCompanyDto System.Collections.Generic.List1[[EXLNT.NursingOps17.NursingOps.Dto.EditCompanyDto, EXLNT.NursingOps17.Application, Version=1.13.0.0, Culture=neutral, PublicKeyToken=null]] -> EXLNT.NursingOps17.NursingOps.Dto.EditCompanyDto at lambda_method(Closure , Object , Object , ResolutionContext ) at AutoMapper.Mapper.AutoMapper.IMapper.Map[TDestination](Object source) at AutoMapper.Mapper.Map[TDestination](Object source) at Abp.AutoMapper.AutoMapExtensions.MapTo[TDestination](Object source) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.AutoMapper\AutoMapper\AutoMapExtensions.cs:line 15 </span>

The last line in the method below generates the error message.

public async Task<EditCompanyDto> GetCompanyForEdit(EntityDto input)
        {
            var query = CompanyEditQuery(input);
            var results = await query.ToListAsync();
            var companyEditDtos = ConvertToCompanyEditDtos(results);
            //The line below generates the mapping error
          return companyEditDtos.MapTo<EditCompanyDto>();
      }

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is NoteHeader is an entity ? If so, please define an DTO for it as well and use it in EditCompanyDto instead of NoteHeader entity.

    And then check if error is fixed.

  • User Avatar
    0
    exlnt created
    [AutoMapTo(typeof(NoteHeader))]
        public class EditNoteHeaderDto : EntityDto
        {
            public NoteHeader Note { get; set; } 
        }
    

    Added noteDTO into companyEditDto:

    [Required]
            public bool ActiveYesNo { get; set; }
    
            public EditNoteHeaderDto Note { get; set; }
    
            public DateTime CreationTime { get; set; }
    

    Still getting the same error:

    <span style="color:#FF0000">AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

    Mapping types: List1 -> EditCompanyDto System.Collections.Generic.List1[[EXLNT.NursingOps17.NursingOps.Dto.EditCompanyDto, EXLNT.NursingOps17.Application, Version=1.13.0.0, Culture=neutral, PublicKeyToken=null]] -> EXLNT.NursingOps17.NursingOps.Dto.EditCompanyDto </span>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I mean you shouldn't use entities in your dtos. You still have NoteHeader in EditNoteHeaderDto. Can you try use it's properties instead of NoteHeader entity in EditNoteHeaderDto.

    And last thing, do you try to map List of EditCompanyDto to a single EditCompanyDto ? Exception message is something like that as far as I can understand.

  • User Avatar
    0
    exlnt created

    Ok I removed all references to my entities in my DTO and it resolved the error, thanks!

    The design pattern used in ABP is something new for me and in the few short weeks that I have been trying to convert my application into ABP design pattern I have learned quite a bit. :)

    If you can please answer a couple of questions to further my understanding of the ABP pattern. I'm starting to understand it but how all the parts work and why they are needed is not quite clear.

    Can you tell me how entities, DTOs and view models used in the ABP solution are intended to be used and what is the purpose of each? If you could just provide a brief description on each one and why they are all used in this manner? Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I suggest you to read this document <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Data-Transfer-Objects">http://aspnetboilerplate.com/Pages/Docu ... er-Objects</a>

    Even all ABP documents if you have time. <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents">http://aspnetboilerplate.com/Pages/Documents</a>

    Documents cover software development best practices and how they are implemented in ABP.