0

We are currently using AutoMapper 5.1.1 and using Explicit Expansion feature. I have a class as a Loan which has property as LoanTypeId-> int and other Property which is of type called Property. In certain cases we want to fetch everything in the property which is street & city and certain cases we want to fetch only street. Is that something Possible. Because If i understand we have to pass "Property" something like this which would fetch everything from Property.

 _loanRepository.Value.GetById(request.EntityId)
            .ProjectTo<DataAttributeResponse>(mapperConfiguration, null, new[] { "LoanTypeId", "Property" })

 CreateMap<Model.Property, Property>()                
            .ForMember(d => d.Street, src => src.MapFrom(l => l.Street))
            .ForMember(d => d.City, src => src.MapFrom(l => l.City));

CreateMap<Model.Loan, DataAttributeResponse>()
 .ForMember(d => d.LoanTypeId, src => src.MapFrom(l => l.LoanTypeID))
 .ForMember(d => d.Property, src => src.MapFrom(l => l.Property))
 .ForAllMembers(opt => opt.ExplicitExpansion());  
Punit
  • 1,347
  • 3
  • 20
  • 39
  • The `MapFrom`-s you have are useless. Also, see [this](https://github.com/AutoMapper/AutoMapper/blob/b26599b821cdbd441a1653cb7ade53c30752db00/src/IntegrationTests/ExplicitExpansion/ExpandMembersPath.cs#L54). – Lucian Bargaoanu Apr 08 '20 at 05:29
  • @LucianBargaoanu - Thanks that works, but my question is that if I have to fetch only City than how can I do it, is that even possible? – Punit Apr 09 '20 at 14:32
  • That's _exactly_ what that example shows. – Lucian Bargaoanu Apr 09 '20 at 16:22
  • @LucianBargaoanu - I did re look at the example and it does r.Class2DTO.Class3DTO which will get everything from Class3DTO but if I only want NameDTO of Class3DTO than? – Punit Apr 10 '20 at 04:17

0 Answers0