5

我发现这个解决方案AutoMapper - 将目标字符串设置为 null 实际上使它成为 string.Empty

但它使用 Initialize 方法,因此所有映射行为都会随着应用程序发生变化:O

我只需要为特定的映射做这件事。

4

1 回答 1

9

Found a solution:

Mapper.Initialize( Conf =>
  {
    Conf.ForSourceType<MyGreatViewModel>().AllowNullDestinationValues = true;
  } );

Thanks guys : )

Take care of your destination field types (remember you need nullable types. e.g. 'Byte?' )

于 2010-02-03T17:05:07.477 回答