Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我发现这个解决方案AutoMapper - 将目标字符串设置为 null 实际上使它成为 string.Empty
但它使用 Initialize 方法,因此所有映射行为都会随着应用程序发生变化:O
我只需要为特定的映射做这件事。
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?' )