Skip null values with custom resolver

前端 未结 4 1647
时光取名叫无心
时光取名叫无心 2020-11-29 08:33

I want to use automapper to map between my public data contracts and my DB models. I have created a class which automatically goes through all the contracts are creates mapp

4条回答
  •  星月不相逢
    2020-11-29 09:18

    For newer versions that utilize the Instance API, use this instead:

    var mappingConfig = new MapperConfiguration(cfg =>
    {
        cfg.CreateMap().ForAllMembers(opt => opt.Condition(
            (source, destination, sourceMember, destMember) => (sourceMember != null)));
    });
    

    Note: This functionality works as of 5.0.2, breaking on later versions as of this writing. Waiting for the next 5.2.x release is recommended if upgrading from 5.0.2.

提交回复
热议问题