Use this tag for version specific questions about AutoMapper 5 - the convention-based object-to-object mapper and transformer library for .NET. When using this tag also include the more generic [automapper] tag where possible.
Questions tagged [automapper-5]
106 questions
24
votes
2 answers
How to use the new IValueResolver of AutoMapper?
I am at a loss as to how to use the new IValueResolver interface in the new version of AutoMapper. Perhaps I used them improperly in the previous versions of AutoMapper...
I have a lot of model classes, some of them are generated from several…

PaddySe
- 468
- 1
- 3
- 11
23
votes
6 answers
EF & Automapper. Update nested collections
I trying to update nested collection (Cities) of Country entity.
Just simple enitities and dto's:
// EF Models
public class Country
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection Cities {…

Akmal Salikhov
- 818
- 3
- 12
- 25
19
votes
2 answers
Mapper not initialized, When Use ProjectTo()
I Use Automapper 5.2.0 In My Project. When I Use ProjectTo() In Code Get This Error:
Mapper not initialized. Call Initialize with Appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you…

Soheil Alizadeh
- 2,936
- 11
- 29
- 56
13
votes
2 answers
AutoMapper throwing "No default constructor" during validation
I have classes to map, but they don't have default constructors, and I don't want them to have. This is because I only map to/from already existing objects.
public class Order
{
public string OrderName { get; set; }
public Order(string name)…

one_mile_run
- 3,264
- 4
- 26
- 29
9
votes
1 answer
Automapper 5.2 ignores ExplicitExpansion if it is configured in Base DTO mapping
Automapper 5.2 (latest by the moment) ignores ExplicitExpansion() configuration if it is configured in the mapping of Base Data Transfer Object. But it still works correctly if mapping is configured directly in Derived DTO. I've got a pair of DTO…

moudrick
- 2,148
- 1
- 22
- 34
9
votes
1 answer
Automapper v5 Ignore unmapped properties
Previously when I used Automapper v3.x ignoring unmapped properties could be done by simply adding a .IgnoreUnmappedProperties() extension which looked like this
public static class AutoMapperExtensions
{
public static IMappingExpression

MartinS
- 6,134
- 10
- 34
- 40
8
votes
2 answers
Polymorphic Mapping of Collections with AutoMapper
TL;DR: I'm having trouble with Polymorphic mapping. I've made a github repo with a test suite that illustrates my issue. Please find it here: LINK TO REPO
I'm working on implementing a save/load feature. To accomplish this, I need to make sure the…

780Farva
- 176
- 1
- 9
7
votes
1 answer
Automapping using open generics and including the source in a ForMember statement
I've recently upgraded from Automapper 4.2.1 to 5.1.1 and am having issues with a previously valid mapping involving open generics.
Previously, within the automapper configuration, I had the following open generic mapping…

rheone
- 1,517
- 1
- 17
- 30
6
votes
1 answer
Automapper - How to map from source child object to destination
I am trying to map from a child object of source to destination(as parent object).
Source Model:
public class SourceBaseResponse where T : new()
{
public string Type { get; set; }
public string Id { get; set; }
public T Attributes {…

Sumesh Kuttan
- 1,333
- 1
- 17
- 40
5
votes
0 answers
Unable to update child entities using Entity Framework Core 2.1
I am a newbie to EF and am struggling to do what seems like a basic update. I have read numerous posts on similar issues. From what I gather this is not currently easy to do in EF Core 2.1 and requires a complex workaround.
Is this actually…

MadMac
- 4,048
- 6
- 32
- 69
5
votes
1 answer
Mapping members with similar names Using Automapper
In a remote db, which I can only read, there are 24 columns in a row for each hour of day. Their names go as P1, P2, ..., P24.
I must copy the values to my own db, which I named column names as H1, H2, ..., H24.
How can I use auto mapper to map…

Doruk
- 884
- 9
- 25
5
votes
3 answers
AutoMapper mapping unmapped properties to Dictionary / ExtensionData
How can I make AutoMapper to map missing unmapped properties to a dictionary inside the destination object? (Like ExtensionData during serialization)
Example:
class Source
{
public int A {get;set;}
public int B {get;set;}
public int C…

Martin Mulder
- 12,642
- 3
- 25
- 54
5
votes
1 answer
AutoMapper 5 Custom Value Resolver "Cannot convert expression type X to return type Y"
I upgraded from an old version of AutoMapper and converted my custom resolvers, but I'm having a hard time.
public class ProductMappingProfile : Profile
{
public ProductMappingProfile()
{
CreateMap()
…

Petrus Theron
- 27,855
- 36
- 153
- 287
5
votes
2 answers
Register AutoMapper 5.1.1 with Castle Windsor
I'm trying to register AutoMapper 5.1.1 with CastleWindsor, but I don't know, where to properly call Mapper.Initialize().
AutoMapper profile:
namespace AutoMapper_DI.Mappings
{
public class WebMappingProfile : Profile
{
…

Michal
- 803
- 2
- 9
- 26
5
votes
1 answer
Automapper with Child List Property Mapping Issue
I am having following Models
Models
public class Dish
{
[Required]
public Int64 ID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
[Required]
public double…

Manoj Sethi
- 1,898
- 8
- 26
- 56