忽略映射一个属性与Automapper [英] Ignore mapping one property with Automapper

查看:3301
本文介绍了忽略映射一个属性与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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆