Reputation: 51
I'm updating my project from AutoMapper version 4.2.1 to 6 and, in the new version, I get an unexpected behaviour.
Classes
class Opportunity : OpportunityLite
{
}
class OpportunityLite
{
public DealerOpportunityLite DealerOpportunity { get; set; }
}
class DealerOpportunity : DealerOpportunityLite
{
public new string BranchCode { get; set; }
}
class DealerOpportunityLite
{
public string BranchCode { get; set; }
}
Mapper Configuration
AutoMapper.Mapper.Initialize(cfg =>
{
cfg.CreateMap<Opportunity, OpportunityLite>();
cfg.CreateMap<DealerOpportunity, DealerOpportunityLite>();
});
Version: 4.2.1
If I execute the following Map:
Opportunity oppLite = new Opportunity
{
DealerOpportunity = new DealerOpportunity
{
BranchCode = "00168"
}
};
var opp = AutoMapper.Mapper.Map<Opportunity, OpportunityLite>(oppLite);
The property value of "opp.DealerOpportunity.BranchCode" is: 00168
From Version 5.0.2 to 6.2.2
In these versions the value of the same property is: null
How can I update AutoMapper to get the same result of version 4.2.1 without adding "ForMember" in the mapping configuration? Unfortunately, I have so many cases of this classes schema.
Upvotes: 2
Views: 123