AutoMapper - NullSubstitution
Sometimes you may want to provide default values if there are null values for a member in the source. Automapper has got a NullSubstitute method in configuration to specify a value for a memeber having null value.
Syntax
NullSubstitute("<provide default value for null>"
Usage
var config = new MapperConfiguration(cfg => { cfg.CreateMap<ModelData, ViewModel>() .ForMember(dest => dest.Name, opt => opt.NullSubstitute("Default Name")); });
Example
In this example, I have provided null for the Name property. But since I have used the NullSubstitute method in the configuration for that member, the value provided there will be mapped to destination object
No Comments
Connecting Azure Blob Storage account using Managed Identity
Posted 12/9/2022Securing Azure KeyVault connections using Managed Identity
Posted 11/26/2022Manage application settings with Azure KeyVault
Posted 11/9/2022Adding Serilog to Azure Functions created using .NET 5
Posted 4/3/2021Learn how to split log data into different tables using Serilog in ASP.NET Core
Posted 4/23/2020