3

for example I have DB view that returns these columns:

Id int
Name nvarchar(200)
PrimaryAddress_Street nvarchar(200)
PrimaryAddress_City nvarchar(200)

And I would like to map it to my DTO:

public class Customer {
  public int Id { get; set; }
  public string Name { get; set; }
  public Address PrimaryAddress { get; set; }
}

public class Address {
  public string Street { get; set; }
  public string City { get; set; }
}

I would like to use AutoMapper to do it. I have mapped IDataRecord to my DTO and then read it directly from ADO.NET DbDataReader:

CreateMap<IDataRecord, Customer>();
var result = Mapper.Map<IDataReader, IEnumerable<Customer>>(reader);

It works for basic properties in Customer DTO. But of course nested PrimaryAddress property is left null because this underscore notation is not build in AutoMapper.

Do you have any ideas how to extend AutoMapper to support this?

Remark: We are using this notation because it works well with Entity Framework and I don't want to have different view for EF and for AutoMapper.

0 Answers0