In AutoMapper 8.0 missing ResolveUsing

Juan Calderon picture Juan Calderon · Dec 5, 2018 · Viewed 12.9k times · Source

Prior to AutoMapper 8.0, I have used this code:

CreateMap<ApplicationRole, RoleViewModel>()
.ForMember(d => d.Permissions, map => map.MapFrom(s => s.Claims))
.ForMember(d => d.UsersCount, map => map.ResolveUsing(s => s.Users?.Count ?? 0))
                    .ReverseMap();

The documentation says that you have to change ResolveUsing for MapFrom, but I have a Error "No propagation Null"

.ForMember(d => d.UsersCount, map => map.MapFrom(s => s.Users?.Count ?? 0))

How I have to resolve it?

Answer

Paw Baltzersen picture Paw Baltzersen · Dec 6, 2018

Replace ResolveUsing with MapFrom, and add one more input parameter to the lambda (TDestination).

.ForMember(d => d.UsersCount, map => map.MapFrom((s,d) => s.Users?.Count ?? 0))