Reputation: 2546
Is there a way to set all properties of a class, that I'm mapping, that is string.Empty
should map to NULL
.
Mapper.CreateMap<TSource, TDest>();
I want that all Properties of TSource
that are string Empty are mapped to NULL
in TDest
corresponding Properties.
I've currently not found a way to globally assign this condition without setting it up for all Properties manually.
EDIT
I need it only for a specific mapping not for all maps defined in my application.
Upvotes: 1
Views: 1530
Reputation: 3516
cfg.CreateMap<string, string>().ConvertUsing(s=>s == "" ? (string)null : s);
Upvotes: 5