CreateMapSource Destination ForMemberdest = destReferenceProperty opt = optConditionsrc = srcReferenceProperty != null; 这个是所有类型的怎么将值类型排除掉值类型为NULL时映射为NULL使用一条语句将引用类型为空时不映射值类型为空时映射
您可以使用以下方式来排除值类型(即结构体)的映射:
CreateMap<Source, Destination>()
.ForMember(dest => dest.ReferenceProperty, opt => opt.Condition(src => src.ReferenceProperty != null))
.ForMember(dest => dest.ValueProperty, opt => opt.Ignore());
在上面的示例中,假设ValueProperty是一个值类型的属性,您可以使用.Ignore()方法来排除它的映射。这样,当ValueProperty的值为null时,它将被映射为默认值。请注意,值类型的默认值通常是0或false。
原文地址: https://www.cveoy.top/t/topic/iE2O 著作权归作者所有。请勿转载和采集!