Use this tag for version specific questions about AutoMapper 2 - 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-2]
113 questions
2
votes
2 answers
Automapper copy based on destination value
I am trying to copy source value only if the destination value is null. I am using the following map
Mapper.CreateMap()
.ForMember(dest => dest.MSOffsetInherited, opt =>
…

user1753466
- 21
- 2
2
votes
0 answers
Automapper Constructor Parameters
I've just started using this and immediately ran into a problem mapping a parameter to a a constructor parameter.
I've tried every example I can find on SO but none seem to work and the documentation doesn't mention this feature as far as I can…

Jammer
- 9,969
- 11
- 68
- 115
2
votes
1 answer
No way to save entity when navigation properties are null, but Ids are filled
I recently migrated my project to MVC4 Web API. Prior to that I used standard MVC controllers. Upon postback of an entity, I used UpdateModel to update the model and then persist it to the database with [dbContext].SaveChanges();
All worked fine,…

RolandG
- 1,269
- 4
- 14
- 21
2
votes
0 answers
AutoMapViewResult from put your controllers on a diet video by Jimmy Bogard
I've watched this video a couple of times and really like the custom ActionResult that he creates that handles mapping your source object to your destination object. My problem is a lot of the time my ViewModel's will have a collection property…

JustinMichaels
- 1,092
- 7
- 12
2
votes
0 answers
AutoMapper: update child property instead of overwritting it
I have a class with a child property:
Person {
string Name;
Address Address {
string Street;
}
}
When I construct new Person object, I want automapper to execute something like:
var person = new Person();
person.Name =…

THX-1138
- 21,316
- 26
- 96
- 160
1
vote
0 answers
Is projection by convention possible with AutoMapper?
I have the following data returned from my database:
Number, AddressStreet, AddressCity, AddressState
My domain objects are as follows:
public class Order
{
public Address Address { get; set; }
public String Number { get; set; }
}
public…

SonOfPirate
- 5,642
- 3
- 41
- 97
1
vote
0 answers
Flat object to nested objects in Automapper
I use Automapper all the time, and for some reason the issue is escaping me. Below is an example of the code I'm using (names have been changed.)
Problem
All objects are mapped but the Keys object.
Code
I have a flat object coming from a WCF…

Omnia9
- 1,563
- 4
- 14
- 39
1
vote
1 answer
Why is a custom resolver needed here (AutoMapper)?
Given the following entity model:
public class Location
{
public int Id { get; set; }
public Coordinates Center { get; set; }
}
public class Coordinates
{
public double? Latitude { get; set; }
public double? Longitude { get; set;…

danludwig
- 46,965
- 25
- 159
- 237
1
vote
1 answer
Automapper and mapping Parent / Child relationships causes a StackOverflow error when Entity Framework generate DynamicProxies?
I have tried many options to get Automapper to correctly map Parent / Child relationships.
Model:
//Entity
public class WorkArea
{
public Guid Id;
public Name {get;set;}
public Guid? ParentWorkAreaId {get;set;} //for entity Framework Foreign…

DDiVita
- 4,225
- 5
- 63
- 117
1
vote
0 answers
Expression 'dest => dest.Request.ID' must resolve to top-level member and not any child object's properties
I want to know why we will get this error and how to resolve it without creating seperating mapping for individual classes.
I have two classes which I want to automap.
I have followed the same approach for other two classes and it is being mapped…

Teja Swaroop
- 185
- 1
- 12
1
vote
1 answer
How to map class entity within json with automapper?
I am storing the Meta information into String fields.
but in DTO object I am mapped with separated class object..
Sample JSON Post object
{
"name": "string",
"directionId": 0,
"description": "string",
"siteId": 0,
"zoneId": 0,
"areaId":…

Abhishek B.
- 5,112
- 14
- 51
- 90
1
vote
1 answer
Automapper - projection with EF generates ugly sql
I'm using the Project() on my IQueryable of "EF Object" to map it to IQueryable of "POCO Model" in the data layer.
The generated SQL statement has 20 LEFT JOINs to the same table. Has anyone seen this behavior?
The object that is being queried…

jDeveloper
- 2,096
- 2
- 21
- 27
1
vote
4 answers
Automapper - Ignore property on base class
I'm having difficulty ignoring a property on an class which inherits from a base class.
Mapper.CreateMap()
.Include()
.ForMember(x => x.Id, o => o.Ignore());
Mapper.CreateMap

JCoder23
- 551
- 1
- 4
- 17
1
vote
0 answers
AutoMapper and Reconciliation?
How can I reconcile a list using auto mapper?
For example given a class
public class SomeEntity
{
public Guid Id {get; set;}
public string Name {get; set;}
}
And an overaching class
public class SomeAggregate
{
public…

Alwyn
- 8,079
- 12
- 59
- 107
1
vote
1 answer
Automapper failing on double? property
I'm using AutoMapper to map Domain objects to ViewModel objects in my controller. Everything was working fine until I tried adding double? properties. I've started getting the following error:
Missing type map configuration or unsupported…

RHarris
- 10,641
- 13
- 59
- 103