自动映射器未正确映射可为空的值

时间:2019-03-14 15:08:30

标签: automapper

Automapper错误地将可为空的类型的空值映射为不可为空的类型的默认值

public class Product
{
   public Guid? ExternalId { get; set; }
}

public class ProductEntity
{
   public Guid? ExternalId { get; set; }
}

如果ProductEntity的ExternalId值为空,则映射到Guid.Empty中的产品结果

这是预期的行为吗?我们没有特殊的映射。

public class ProductProfile : Profile
{
   public ProductProfile()
   {
      CreateMap<ProductEntity, Product>();
      CreateMap<Product, ProductEntity>();
   }
}

我们正在使用Automapper 7.0.1

0 个答案:

没有答案