Paul Deen
Paul Deen

Reputation: 455

Automapper: How to ignore a member in VB.NET

I'm using Automapper in a VB.NET project, and am trying to make it ignore a member. I can see how to do this in C#, but not in VB.NET. Does anyone have a quick example of using the ForMember method.

Thanks,

Paul

Upvotes: 3

Views: 2107

Answers (2)

Guillaume
Guillaume

Reputation: 1105

There is now (AutoMapper 2.0) an IgnoreMap attribute.

Upvotes: 1

Patricia
Patricia

Reputation: 7802

Here's how you do it :)

Mapper.CreateMap(Of incomingModel, outgoingModel)().ForMember(Function(x) x.FieldToIgnore, Sub(y) y.Ignore())

The thing that is important, and likely what messed up you is the Sub instead of the function for the second part.

this also only works in vs2010. older versions you can't do it.

Upvotes: 9

Related Questions