I’m looking for a way to handle this either via a global Mapperly configuration or a mapper-level configuration, without having to make widespread nullable changes across the domain and DTO models.
For context, here’s a simple example:
public partial class HrCountryWithNavigationPropertiesToDtoMapper
: MapperBase<HrCountryWithNavigationProperties, HrCountryWithNavigationPropertiesDto>
{
public override partial HrCountryWithNavigationPropertiesDto Map(HrCountryWithNavigationProperties source);
public override partial void Map(HrCountryWithNavigationProperties source, HrCountryWithNavigationPropertiesDto destination);
}
public class HrCountryWithNavigationProperties
{
public HrCountry HrCountry { get; set; }
public HrMailCountry HrMailCountry { get; set; }
}
public class HrCountryWithNavigationPropertiesDto
{
public HrCountryDto HrCountry { get; set; }
public HrMailCountryDto HrMailCountry { get; set; }
}
During runtime, if HrMailCountry (or any navigation property) is null, Mapperly throws a NullReferenceException. This differs from AutoMapper’s behavior, where null navigation properties were implicitly ignored or mapped to default values. Making these properties nullable (HrMailCountry?, HrMailCountryDto?) resolves the issue, but that would require extensive refactoring across the solution, which I’d like to avoid if possible.
I didn't find this fix in the ABP documentation anywhere. Could you please share the documentation here so that I can have a look. Thanks!
Hi, I've shared the application code for one of the module with you. Please have a look. It's a production app, not a test app, so I cannot share the whole source code with you. Thanks!
I can give you the remote access of my system, let me know when you're comfortable to connect Thanks!
Yes, it's already configured
[DependsOn(
typeof(IseCoreDomainModule),
typeof(IseCoreApplicationContractsModule),
typeof(AbpDddApplicationModule),
typeof(AbpMapperlyModule)
)]
public class IseCoreApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddMapperlyObjectMapper<IseCoreApplicationModule>();
}
}
Trying to do: var filter = ObjectMapper.Map<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>(input); but getting error.
Here is the configuration for mapperly in file IseCoreApplicationMappers.cs
[Mapper]
public partial class HrMissionaryLookupRequestDtoToHrMissionaryLookupFilterMapper
: MapperBase<HrMissionaryLookupRequestDto, HrMissionaryLookupFilter>
{
public override partial HrMissionaryLookupFilter Map(HrMissionaryLookupRequestDto source);
public override partial void Map(
HrMissionaryLookupRequestDto source,
HrMissionaryLookupFilter destination
);
}