I cannot get the following to work, where array is an array of CustomerContract's:
Mapper.Map<IEnumerable<Customer>>(array);
Mapper.Map<IEnumerable<CustomerContract>, IEnumerable<Customer>>(array);
Mapper.Map<Array, List<Customer>>(array);
In my mind the first example should be enough, but i can not get either to work. I have read the configuration wiki of automapper (https://github.com/AutoMapper/AutoMapper/wiki/Configuration), but i do not understand why this should be necessary. Everything Automapper needs is defined in the command. Which type it is (both object and that it is a list), and which object i want it to map to.
Am i just not understanding the core concept of Automapper?
My exception sounds like this:
Missing type map configuration or unsupported mapping.
Mapping types:\r\nCustomerContract -> Customer\r\nStimline.Xplorer.Repository.CustomerService.CustomerContract -> Stimline.Xplorer.BusinessObjects.Customer
Destination path: List`1[0]
Source value: Stimline.Xplorer.Repository.CustomerService.CustomerContract
How do I use AutoMapper? First, you need both a source and destination type to work with. The destination type's design can be influenced by the layer in which it lives, but AutoMapper works best as long as the names of the members match up to the source type's members.
Where do I configure AutoMapper? ¶ Configuration should only happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.
Yes, or you can call CreateMap<ModelClass, ViewModelClass>(). ReverseMap() .
You're mapping to IEnumerable... Automapper can map to a concrete type not an interface.
First register your mapping (see the "Missing type map configuration or unsupported mapping") You must use CreateMap once for performance
Mapper.CreateMap<something, somethingelse>();
Instead of:
Mapper.Map<IEnumerable<Customer>>(array);
Try this:
Mapper.Map<List<Customer>>(array);
or
Mapper.Map<Customer[]>(array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With