忽略映射一个属性与Automapper [英] Ignore mapping one property with Automapper
问题描述
我使用Automapper,我有以下情形:
类OrderModel有一个名为产品名称属性,是不是在数据库中。
所以,当我尝试做的映射有:
I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with:
Mapper.CreateMap<OrderModel, Orders>();
它会产生一个例外:
It generates an exception :
关于Project.ViewModels.OrderModel以下1属性不会映射:产品名称
"The following 1 properties on Project.ViewModels.OrderModel are not mapped: 'ProductName'
我在 AutoMapper的维基阅读预测相反的情况(额外的属性上目的地,而不是源这实际上是我的情况)
I've read at AutoMapper's Wiki for Projections the opposite case (the extra attribute is on the destination, not in the source which is actually my case )
如何才能避免automapper使这个属性的映射?
How can I avoid automapper to make the mapping of this property?
推荐答案
从吉米·博加德: CreateMap&LT;富,酒吧及GT;()ForMember(X =&GT; x.Blarg,选择=&GT; opt.Ignore());
这是在<一个href=\"http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/01/22/automapper-the-object-object-mapper.aspx\">one在他的博客的意见。
这篇关于忽略映射一个属性与Automapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!