1

Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters

AutoMapper created this type map for you, but your types cannot be mapped using the current configuration. CustomerDto -> Customer_F18BD0407D7AB3084DFC14364CBC838E797CB114E45768DA5EB22B4A1CC94C26 (Destination member list) WebApiCollection.DTO.CustomerDto -> System.Data.Entity.DynamicProxies.Customer_F18BD0407D7AB3084DFC14364CBC838E797CB114E45768DA5EB22B4A1CC94C26 (Destination member list)

Unmapped properties: _entityWrapper

var customerInDb = _dbContext.Customers.SingleOrDefault(p => p.Id == customerDto.Id); if (customerInDb == null) return NotFound();

            customerInDb = Mapper.Map(customerDto, customerInDb);

2 Answers2

0

Have you tried?

customerInDb = Mapper.Map<Customer>(customerDto);
CoderMan
  • 59
  • 1
  • 6
0

This can occur when the fields between the Dto and the Entity class don't line up. For example. My Dto contains two fields

public class ReworkDto: FullAuditEntity
{
    public string WorkOrderNumber { get; set; }
    public string WorkOrderBarcode { get; set; }
}

Those two fields are also in the entity class but the entity class also includes a navigation property (ReworkDetails)

[Table("Quality_Rework")]
public class QualityRework : FullAuditEntity
{
    [Required, Column(Order = 8)]
    public virtual string WorkOrderNumber { get; set; }

    [Required, Column(Order = 9)]
    public virtual string WorkOrderBarcode { get; set; }

    public virtual ICollection<QualityReworkDetail> ReworkDetails { get; set; }
}

The particular error for this post would surface if I tried updating, using the following code

private void Update(ReworkDto entityDto)
    {
        try
        {
            var entityToUpdate = DbContext.QualityRework.FirstOrDefault(x => x.Id == entityDto.Id);
            var updateRework = _autoMapper.Map(entityDto, entityToUpdate);
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc);
            throw;
        }
    }

To avoid getting the error I would need to CreateMap (AutoMapperModule.cs), instructing AutoMapper that when mapping between Dto -> Entity to Ignore() the ReworkDetails field.

CreateMap<domain.DTO.Quality.ReworkDto, infrastructure.Entities.Quality.QualityRework>()
                .ForMember(dest => dest.ReworkDetails, opt => opt.Ignore());
Geovani Martinez
  • 2,053
  • 2
  • 27
  • 32