NuGet Package Manager: ‘AutoMapper’ already has a dependency defined for ‘Microsoft.CSharp’

The problem is that your NuGet Package Manager is too old. You need NuGet 2.12 since this supports the newer .NETStandard frameworks that the AutoMapper 5.0.1 NuGet package is using. The AutoMapper has a group dependency which specifies a target framework of .NETStandard. Since your version of NuGet Package Manager is too old it does … Read more

Dictionary map to an object using Automapper

AutoMapper maps between properties of objects and is not supposed to operate in such scenarios. In this case you need Reflection magic. You could cheat by an intermediate serialization: var data = new Dictionary<string, string>(); data.Add(“Name”, “Rusi”); data.Add(“Age”, “23”); var serializer = new JavaScriptSerializer(); var user = serializer.Deserialize<User>(serializer.Serialize(data)); And if you insist on using AutoMapper … Read more

Simple Automapper Example

1- Change the GroupDto to be like this: [DataContract] public class GroupDto { [DataMember] public int id { get; set; } [DataMember] public string name{ get; set; } [DataMember] public List<UserDTO> Users { get; set; } } 2- Create your mappings : Mapper.CreateMap<User, UserDto>(); Mapper.CreateMap<UserDto, User>(); // Only if you convert back from dto to … Read more

Using AutoMapper to unflatten a DTO

This also seems to work for me: Mapper.CreateMap<PersonDto, Address>(); Mapper.CreateMap<PersonDto, Person>() .ForMember(dest => dest.Address, opt => opt.MapFrom( src => src ))); Basically, create a mapping from the dto to both objects, and then use it as the source for the child object.

Possible to use AutoMapper to map one object to list of objects?

You will need these three mapings with one custom converter: Mapper.CreateMap<Event, EventDTO>(); // maps message and event id Mapper.CreateMap<EventLog, EventDTO>(); // maps system id and user id Mapper.CreateMap<EventLog, IEnumerable<EventDTO>>() .ConvertUsing<EventLogConverter>(); // creates collection of dto Thus you configured mappings from Event to EventDTO and from EventLog to EventDTO you can use both of them in … Read more

Copy object to object (with Automapper ?)

As I understand the question, OP does not want to clone person2 into a new instance of Person, but is asking for how to copy the contents of person2 into an already existing instance (person1) of Person. There is an overload of AutoMapper’s Mapper.Map method that does this for you: Mapper.CreateMap<Person, Person>(); Mapper.Map<Person, Person>(person2, person1); … Read more

Automapper missing type map configuration or unsupported mapping – Error

Where have you specified the mapping code (CreateMap)? Reference: Where do I configure AutoMapper? If you’re using the static Mapper method, 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.asax file for ASP.NET applications. If the configuration isn’t registered … Read more