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
80
votes
1 answer

How to Map String Literal to Destination Property

I'd like to be able to do something like this using automapper: Mapper.CreateMap() .ForMember d.Member, "THIS STRING">(); I'd like d.Member to always be "THIS STRING" and not be mapped from any particular member from…
Rick Eyre
  • 2,355
  • 4
  • 20
  • 26
75
votes
3 answers

Automapper copy List to List

I have these classes: public class Person { public int Id{ get; set ;} public string FirstName{ get; set ;} public string LastName{ get; set ;} } public class PersonView { public int Id{ get; set ;} public string FirstName{ get;…
TheBoubou
  • 19,487
  • 54
  • 148
  • 236
60
votes
4 answers

How to configure Conditional Mapping in AutoMapper?

Suppose I have the following entities (classes) public class Target { public string Value; } public class Source { public string Value1; public string Value2; } Now I want to configure Auto Map, to Map Value1 to Value if Value1 starts…
Alwyn
  • 8,079
  • 12
  • 59
  • 107
58
votes
5 answers

AutoMapper: What is the difference between MapFrom and ResolveUsing?

Ignoring the ResolveUsing overloads that take an IValueResolver, and looking only at these 2 methods: void ResolveUsing(Func resolver); void MapFrom(Expression> sourceMember); The main difference…
danludwig
  • 46,965
  • 25
  • 159
  • 237
44
votes
2 answers

Using AutoMapper to map the property of an object to a string

I have the following model: public class Tag { public int Id { get; set; } public string Name { get; set; } } I want to be able to use AutoMapper to map the Name property of the Tag type to a string property in one of my viewmodels. I have…
marcusstarnes
  • 6,393
  • 14
  • 65
  • 112
42
votes
6 answers

How to configure Auto mapper in class library project?

I am using auto mapping first time. I am working on c# application and I want to use auto mapper. (I just want to know how to use it, so I don't have asp.net app neither MVC app.) I have three class library projects. I want to write transfer…
bnil
  • 1,531
  • 6
  • 35
  • 68
35
votes
3 answers

Mapping one source class to multiple derived classes with automapper

Suppose i have a source class: public class Source { //Several properties that can be mapped to DerivedBase and its subclasses } And some destination classes: public class DestinationBase { //Several properties } public class…
Erik Nordenhök
  • 645
  • 1
  • 5
  • 14
32
votes
2 answers

Is this a breaking change between AutoMapper 2.0.0 and 2.2.0?

I updated from AutoMapper 2.0.0 to 2.2.0 today and realized the update broke some code. Wanted to ask about it here before posting as an issue on the automapper github site. One of my destination types initializes a collection property like…
danludwig
  • 46,965
  • 25
  • 159
  • 237
32
votes
6 answers

Automapper expression must resolve to top-level member

I am using automapper to map source and destination objects. While I map them I get the below error. Expression must resolve to top-level member. Parameter name: lambdaExpression I am not able resolve the issue. My source and destination objects…
28
votes
1 answer

Automapper with nested child list

I have two classes below: public class Module { public int Id { get; set; } public string Name { get; set; } public string ImageName { get; set; } public virtual ICollection Pages { get; set; } } public class ModuleUI { …
tobias
  • 1,502
  • 3
  • 22
  • 47
28
votes
2 answers

AutoMapper using the wrong constructor

Today I upgraded a fully functioning application using AutoMapper v1.1 to now use AutoMapper v2.1 and I am coming across some issues that I never encountered using the previous version. Here is an example of my code mapping back from Dto to Domain…
Mark Vickery
  • 1,927
  • 3
  • 22
  • 34
20
votes
6 answers

Circular reference causing stack overflow with Automapper

I'm using Automapper to map my NHibernate proxy objects (DTO) to my CSLA business objects I'm using Fluent NHibernate to create the mappings - this is working fine The problem I have is that the Order has a collection of OrderLines and each of these…
Charleh
  • 13,749
  • 3
  • 37
  • 57
13
votes
2 answers

AutoMapper -- inheritance mapping not working, same source, multiple destinations

Can I use inheritance mapping in AutoMapper (v2.2) for maps with the same Source type but different Destination types? I have this basic situation (the real classes have many more properties): public abstract class BaseViewModel { public int…
kdawg
  • 2,019
  • 21
  • 31
9
votes
3 answers

Automapper map from one object to nested objects

What is the best way to map inner objects with Automapper 2.0 Use the solution in this question (Automapper 1.0) Create a Custom Value Resolvers ? public class DTOObject { // MainObject public int Id { get; set; } public string Name {…
Bjarki Heiðar
  • 3,117
  • 6
  • 27
  • 40
9
votes
3 answers

AutoMapper and flattening nested arrays

I'm trying to use AutoMapper to flatten multiple levels of arrays. Consider the following source classes: class X { public string A { get; set; } public Y[] B { get; set; } } class Y { public string C { get; set; } public Z[] D {…
Bryan Slatner
  • 1,588
  • 2
  • 16
  • 19
1
2 3 4 5 6 7 8