Base solution for your next web application
Open Closed

AutoMapper.AutoMapperMappingException #3880


User avatar
0
poolman created

I am getting the following error when trying to edit my entity Customer"

AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
Customer -> CustomerEditDto

App Service

public async Task<GetCustomerForEditOutput> GetCustomerForEdit(NullableIdDto<Guid> input)
{
    var output = new GetCustomerForEditOutput{ };
    if (!input.Id.HasValue)
    {
        //Creating a new customer
        output.Customer = new CustomerEditDto
        {
            IsActive = true
        };
    }
    else
    {
        //Editing an existing customer
        var customer = await _customerRepository.GetAsync(input.Id.Value);
        output.Customer = ObjectMapper.Map<CustomerEditDto>(customer);
    }
    return output;
}

GetCustomerForEditOutput

public class GetCustomerForEditOutput
{
    public CustomerEditDto Customer { get; set; }
}

CustomerEditDto

[AutoMapTo(typeof(Customer))]
public class CustomerEditDto : IPassivable
{
    /// <summary>
    /// Set null to create a new customer. Set customer's Id to update a customer
    /// </summary>
    public Guid? Id { get; set; }

    [Required]
    [MaxLength(Customer.MaxFirstNameLength)]
    public virtual string FirstName { get; set; }

    [Required]
    [MaxLength(Customer.MaxLastNameLength)]
    public virtual string LastName { get; set; }

    [Required]
    [MaxLength(Customer.MaxEmailAddressLength)]
    public virtual string EmailAddress { get; set; }

    [Required]
    [MaxLength(Customer.MaxPhoneLength)]
    public virtual string Phone { get; set; }

    public bool IsActive { get; set; }
}

I have a feeling it is something stupid, but I just can't see it. Any help would be appreciated. :D


3 Answer(s)
  • User Avatar
    0
    strix20 created

    Shouldn't it be AutoMapFrom, based on the mapping you are doing?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @strix20 is right. You can also use AutoMap attribute which provides two way binding.

  • User Avatar
    0
    poolman created

    <cite>ismcagdas: </cite> @strix20 is right. You can also use AutoMap attribute which provides two way binding.

    Thank you both! I knew it was something stupid. :oops: