Questions tagged [automapper-6]

Use this tag for version specific questions about AutoMapper 6 - 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.

117 questions
31
votes
11 answers

Automapper - Mapper already initialized error

I am using AutoMapper 6.2.0 in my ASP.NET MVC 5 application. When I call my view through controller it shows all things right. But, when I refresh that view, Visual Studio shows an error: System.InvalidOperationException: 'Mapper already…
Rahmat Ali
  • 1,430
  • 2
  • 17
  • 29
29
votes
2 answers

AutoMapper: What is the difference between ForMember() and ForPath()?

I am reading AutoMapper's ReverseMap() and I can not understand the difference between ForMember() and ForPath(). Implementations was described here. In my experience I achieved with ForMember(). See the following code where I have configured…
Adam Shakhabov
  • 1,194
  • 2
  • 14
  • 35
9
votes
3 answers

AutoMapper: How to map only matching property names and ignore all others?

I am new to AutoMapper and using version 6.2.2. I am trying to map a view model to an entity (also using Entity Framework). I want to update only the properties that exist in both the viewmodel and the entity. The entity has other navigational…
Rokal
  • 485
  • 3
  • 7
  • 16
6
votes
2 answers

Automapper does not map properly null List member, when the condition != null is specified

There is a problem when I try to map a null list (member) of an object, considering that I specified: .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null )); cfg.AllowNullCollections = true; // didn't help…
4
votes
0 answers

CompileMappings at Startup with AutoMapper extensions for ASP.NET Core

I am using the AutoMapper extensions for ASP.NET Core, so am registering Automapper at Startup like in this official example. I would like to compile mappings at startup rather letting Automapper do the default lazy compilation, but can't seem to…
DanO
  • 911
  • 1
  • 8
  • 16
4
votes
1 answer

Automapper - map abstract to abstract

Source classes: public abstract class ApplicationDriverEquipmentFormAbstractVM { [StringLength(256)] public string Make { get; set; } [StringLength(256)] public string Model { get; set; } [StringLength(256)] public string…
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
3
votes
2 answers

Automapper - need to map a parent property when mapping children

The basic problem is that I have properties on my source parent entities that I need to map to my destination child DTOs when the child entities are mapped to the destination child DTOs. The child entities do not have navigation properties to their…
Bobby Ortiz
  • 3,077
  • 7
  • 35
  • 45
3
votes
1 answer

How to prevent AutoMapper from initializing destination JObject member when source is null

Suppose you have the following classes: public class Source { public string Data { get; set; } } public class Destination { public JObject Data { get; set; } } And you configure AutoMapper using this: Mapper.Initialize( cfg => { …
Ben Randall
  • 1,205
  • 10
  • 27
3
votes
0 answers

AutoMapper 6.2.2 throwing StackOverflowException when mapping objects with circular references (although corresponding properties are NULL)

We use EntityFramework 6.2.0 in conjunction with Automapper 6.2.2 to map between entities and DTOs. Unfortunately, with some of these mappings the System.StackOverflowException occurs again and again. After extensive research we have already tried…
3
votes
2 answers

AutoMapper overwrites recursive type

I have a Dto that looks somewhat like this: class TypeDto { int Id {get; set;} string Name {get; set;} string DisplayName {get; set;} IEnumerable Children {get; set;} } Now I need to map to it from two different…
V0ldek
  • 9,623
  • 1
  • 26
  • 57
3
votes
1 answer

How to map EF Dynamic Proxy with Automapper 6.1.1+

I am trying to map an Entity Framework model to a view model after saving. //Map my incoming VM to a DTO and save it Inquiry savedInquiry = InquiryLogic.Save(mapper.Map(inquiryVM)); //Map the returned Inquiry back to a VM and return…
3
votes
2 answers

Automapper flattened DTO to Parent with Child Collection

I have a flattened DTO which I need to map to a Parent with Children relationship. I'd like to do this via AutoMapper as I'm using it in other places and it works great. I've seen examples of mapping a Parent and Child but not when the Child is a…
Billy Rudasill
  • 105
  • 2
  • 11
3
votes
1 answer

Automapper: i need to call "CreateMap" for every single copy of Entity - DTO?

I'm using Automapper (6.2.1) for convert a hierarchy of Entity objects: class Entity1 {} class Entity2 : Entity1 {} class Entity3 : Entity1 {} To a corresponding hierarchy of DTO objects: class EntityDTO1 {} class EntityDTO2 : EntityDTO1 {} class…
Pippi
  • 313
  • 1
  • 4
  • 18
3
votes
1 answer

Automap objects from different language

I'm trying to find a way to have a mapping configuration that can map between totally different names from a list. Our database is in Dutch and scaffolding tooling (like scaffold-dbcontext) keeps the table names for the DTO's. Outside our db…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
3
votes
1 answer

Automapper nested Collections without setter

I have this code snippet running on LinqPad (C# program) with Automapper Nuget package 6.1.1 already included: void Main() { Mapper.Initialize(cfg => { cfg.CreateMap().ReverseMap(); }); …
ferpega
  • 3,182
  • 7
  • 45
  • 65
1
2 3 4 5 6 7 8