且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将同名字段映射到自动映射器中的不同字段

更新时间:2023-01-09 11:30:50

这里发生的事情是 Name 是通过 构造函数.避免这种情况的一个简单方法是告诉 AM 要使用什么构造函数:

What happens here is that Name is mapped through the constructor. A simple way to avoid that is to tell AM what constructor to use:

 CreateMap<Match, ViewCompany>().ConstructUsing(source=>new ViewCompany());