'Map from inner property to destination class

I have automapper profile

Here is mappings

 CreateMap<CompaniesHouseMatchResult, InputCompaniesHouseSearchResult>()
        .ForMember(x => x.CompanyName, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.Title))
        .ForMember(x => x.CompanyNumber, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.CompanyNumber))
        .ForMember(x => x.CompanyStatus, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.CompanyStatus))
        .ForMember(x => x.CompanyStatus, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.CompanyStatus))
        .ForMember(x => x.CompanyStatus, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.CompanyStatus))
        .ForMember(x => x.JobId, opt => opt.Ignore())
        .ForMember(x => x.Id, opt => opt.Ignore())
        .ForMember(x => x.SupplierKey, opt => opt.Ignore())
        .ForMember(x => x.DateOfCessation, opt => opt.Ignore())
        .ForMember(x => x.DateOfCreation, opt => opt.Ignore())
        .ForMember(x => x.DateOfCreation, opt => opt.Ignore())
        .ForMember(x => x.InputCompaniesHouseSicCodes, opt => opt.Ignore())
        .ForMember(x => x.InputCompaniesHousePreviousNames, opt => opt.Ignore());

Source class looks like this

  using Ptco.DataPipeline.Services.Matching;
using Ptco.DataPipeline.Services.Matching.Models;
using Ptco.External.CompanyHouseApi.Models.Response;

namespace Ptco.DataPipeline.Services.Services.CompaniesHouse;

public record CompaniesHouseMatchResult(Item CompaniesHouseItem, MatchResult MatchResult);

So to match CompanyName I need to write

 .ForMember(x => x.CompanyName, opt => opt.MapFrom(aa => aa.CompaniesHouseItem.Title))

How I can math it without specifying child?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source