Questions tagged [automapper-2]

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.

113 questions
9
votes
1 answer

AutoMapper Custom Type Converter not working

I am using Troy Goode's PagedList to provide paging information in my WebApi. His package returns an IPagedList that implements IEnumerable but also contains custom properties such as IsLastPage, PageNumber, PageCount, etc. When you try to return…
Brian McCord
  • 4,943
  • 7
  • 32
  • 44
8
votes
2 answers

Am I using Automapper 2.0's Include functionality correctly?

Either I'm not, or it isn't working... I have a single Source class that I want to map to multiple views that inherit from each other. Basically the base class is the Detail, and the child class is Edit or Update which use all the same data as…
CodeRedick
  • 7,346
  • 7
  • 46
  • 72
8
votes
1 answer

How to tell Automapper to check if all source properties have destination properties

We have two classes: public class Foo { public int A { get; set; } public int B { get; set; } public int C { get; set; } } public class Bar { public int A { get; set; } public int B { get; set; } } and mapping configuration …
jjjjj
  • 339
  • 4
  • 11
7
votes
2 answers

How to map to "this" with AutoMapper in constructor

I have a source type which have properties and a destination type which have exactly the same properties. After I configure one simple mapping for AutoMapper like: Mapper.CreateMap(); I would like to have a…
g.pickardou
  • 32,346
  • 36
  • 123
  • 268
7
votes
2 answers

Projection using contextual values in AutoMapper

I'm currently evaluation whether AutoMapper can be of benefit to our project. I'm working on a RESTful Web API using ASP.NET Web API, and one of the things I must return is a resource that contains links. Consider this simplified example, using the…
Dave Van den Eynde
  • 17,020
  • 7
  • 59
  • 90
6
votes
2 answers

Automapper map one property to multiple

I am facing a challenge with AutoMapper between my source object and destination object. I will try to explain the sittuation. On my src object I have an string that according to its lenght it should be mapped to multiple properties of my…
JAVH
  • 155
  • 1
  • 3
  • 13
6
votes
1 answer

AutoMapper not working with collection of derived classes

I'm facing a problem with AutoMapper 2.1.267.0 when working with objects containing collections of derived classes. I've isolated my problem in a simpler scenario with the following classes: public class ClassABase { public string Name { get;…
peflorencio
  • 2,284
  • 2
  • 32
  • 40
6
votes
1 answer

AutoMapper mapping using interface vs concrete map

I don't think this is possible, but it's worth the question, I suppose. I have the following types that share an interface (I promise, this isn't the same question I've asked before). public interface ICustomer; public class CustomerBO :…
Lao
  • 151
  • 1
  • 8
5
votes
2 answers

Automapper map from Source to Destination containing List of Objects

I have to create a Mapping with automapper. Public class Source { public string Id; public string Firstname; public string Lastname; } Destination is Public class Destination { public string Id; public Person[]…
user2739679
  • 827
  • 4
  • 14
  • 24
5
votes
1 answer

AutoMapper - Why it is overwriting whole object?

I don't understand why it's overwriting my whole object. The reason is that I get my User object from db an I want to assign new values from DTO. Instead of just adding those new values it's creating new object that has new values but all previous…
Stan
  • 25,744
  • 53
  • 164
  • 242
5
votes
1 answer

AutoMapper with ValueFormatter

I'm learning how to use AutoMapper, and I'm having problems using it with ValueFormatter. Here's simple example in Console, where I'm unable to use it with NameFormatter: class Program { static void Main(string[] args) { …
Janez Lukan
  • 1,439
  • 1
  • 12
  • 28
5
votes
2 answers

Map list to existing list in Automapper using a key

Automapper easily handles mapping one list of object types to another list of different objects types, but is it possible to have it map to an existing list using an ID as a key?
ozz
  • 5,098
  • 1
  • 50
  • 73
4
votes
1 answer

Looking for AutoMapper v2 documentation

I just downloaded the source code of AutoMapper to do some debugging. When I built the sources I noticed it has 2.0 as a version number. I know Jimmy Bogard was working on a second version, with some nice features such as two-way mapping. But is…
Gerrie Schenck
  • 22,148
  • 20
  • 68
  • 95
4
votes
1 answer

AutoMapper complex object mapping - mapping a list

I have the following classes. The domain models are created by entity framework and i am using POCO. public class Customer { public int Id { get; set; } public string Name { get; set; } public DateTime CreatedDate{ get; set; } public…
ministrymason
  • 1,783
  • 2
  • 20
  • 33
4
votes
2 answers

AutoMapper: Set all properties of destination object to default if source object is null for specified types

Is it possible to configure AutoMapper to set all properties to default value in case if the source object is null for specified classes? I know that I should use Mapper.AllowNullDestinationValues = false; to do what I want for all classes in…
dmolokanov
  • 41
  • 1
  • 3