Recently I updated automapper 5+ version and realized that IValueresolver does not work as expected for Nullable type Guid.
I have created a value resolver as follows:
public class GanttTaskParentIdResolver : IValueResolver<GanttTask, Task, Guid?>
{
private IUow Uow;
public GanttTaskParentIdResolver(IUow _uow)
{
Uow = _uow;
}
public Guid? Resolve(GanttTask source, Task destination, Guid? member, ResolutionContext context)
{
if (source.parentIdRaw != null && source.parentIdRaw != 0)
{
var task = Uow.Tasks.GetAll().Where(con => con.Id == source.parentIdRaw).FirstOrDefault();
return task.GUID;
}
else return null;
}
}
and Mapping configuration as follows:
cfg.CreateMap<GanttTask, Task>()
.IgnoreAllNonExisting()
.ForMember(dst => dst.Children, opt => opt.MapFrom(s => s.Children))
.ForMember(dst => dst.ParentId, opt => opt.ResolveUsing<GanttTaskParentIdResolver>())
.ForMember(dst => dst.CalendarId, opt => opt.ResolveUsing<GanttTaskCalendarIdResolver>());
The dst.ParentId is Nullable Guid. It does not trigger GanttTaskParentIdResolver for resolving and always gives null for ParentId.
Anyone experienced the same issue?
Update - i tested for nullable int and it works. it seems a issue with nullable Guid