Make Overload of a CreateMap

17 views
Skip to first unread message

riaz...@koderlabs.com

unread,
May 6, 2016, 3:27:49 AM5/6/16
to AutoMapper-users
Hey,

I have been working on a project and due to some strange requirements I was wondering if I can make an overload of CreateMap function.

I have a "MyEntity" class and "MyViewModel" class, and I am using AutoMapper to convert "MyEntity" to "MyViewModel", now I have two scenarios to convert them,

Scenario 1: Map all the fields regardless of any condition (When I am mapping data to show on edit page)

Scenario 2: Map some fields conditionally, and Ignore some fields regardless of anything (When I am mapping the data saved in db on the data posted back from edit form)

So, Can i make another CreateMap? or an overload of CreateMap<MyEntity, MyViewModel>? or a workaround?

Thanks in Advance, Any help will be aprreciated.

Regards,
Riaz Raza

Michael Powell

unread,
May 6, 2016, 6:35:57 PM5/6/16
to AutoMapper-users, riaz...@koderlabs.com


On Friday, May 6, 2016 at 3:27:49 AM UTC-4, riaz...@koderlabs.com wrote:
Hey,

I have been working on a project and due to some strange requirements I was wondering if I can make an overload of CreateMap function.

I have a "MyEntity" class and "MyViewModel" class, and I am using AutoMapper to convert "MyEntity" to "MyViewModel", now I have two scenarios to convert them,

The new version supports mapper "configurations"; assuming your scenario concerns are separated, you can provide two different configurations. I am currently doing just that, all over the place, throughout my MVC controllers, and it works beautifully.

riaz...@koderlabs.com

unread,
May 6, 2016, 9:30:51 PM5/6/16
to AutoMapper-users, riaz...@koderlabs.com
Thanks Mr Powell,

Can you please guide me with a little code snippet to provide two different configurations in different scenarios.

Your help is highly appreciated.

Jimmy Bogard

unread,
May 7, 2016, 12:39:14 PM5/7/16
to automapp...@googlegroups.com
The MapperConfiguration object can just be instantiated by itself. Just create two of those with different CreateMap calls and store the config instances where they're easy to get at. Static fields etc.
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages