Reputation: 2737
I using Automapper in my project
In mapper, I map the string to ICollection
.
Here is how I do it
.ForMember(x => x.PropertyImages,
opt => opt.MapFrom(aa => aa.Attachments.Split(';', StringSplitOptions.None).ToList()));
But if string is empty. I got error
object not set to an instance of an object
How I can make conditional mapping, only if string not null
Upvotes: 0
Views: 880
Reputation: 851
You can use ternary operator to check string
.ForMember(x => x.PropertyImages,
opt => opt.MapFrom(aa => !string.IsNullOrEmpty(aa.Attachments) ? aa.Attachments.Split(';', StringSplitOptions.None).ToList() : new List<string>()));
Upvotes: 1