Questions tagged [automapper]

A convention-based object-to-object mapper and transformer for .NET

automapper
Filter by
Sorted by
Tagged with
2 votes
1 answer
3k views

Is there a way to use AutoMapper for mongo c# projection expression when using aggregate()?

I'm trying to avoid doing manual mappings of my models to viewmodels while using mongo c# driver (v2.7.2) aggregation and projection. Instead of doing the mapping for the projection manually var ...
nik's user avatar
  • 1,479
2 votes
2 answers
776 views

Mapping with generic destination doesn't work?

I'm trying to build out a hierarchy of mapping profiles to simplify creating mappings for new objects that fit in this hierarchy. But I'm having trouble getting some mappings to work. A mapping I ...
Jeff Mercado's user avatar
0 votes
1 answer
193 views

Strange behavior of Automapper when property type is ignored

After I saw how to ignore a property type with Automapper, I have tried it in a test project. It turns out that the property of a specific type is ignored properly, but when invoking ...
meJustAndrew's user avatar
  • 6,281
2 votes
4 answers
15k views

AutoMapper C# - Set default value for all unmapped string in destination

I'm new to AutoMapper, and trying convert object to bigger (means more fields) object. I'm looking for a way to set default value for all destination's string fields. Currently couldn't find a way to ...
Roni's user avatar
  • 381
0 votes
0 answers
355 views

Automapper deep mapping

I am using EFCore 2.2 and automapper 8.0.0. I have table named folders and it has another table named folderReferences and the code for folder table is: public Guid Id { get; set; } public virtual ...
SolarCore's user avatar
  • 133
1 vote
2 answers
2k views

DotNet Core Console Application: AutoMapper

Hello I am using AutoMapper in DotNet Core Console Application StartUp file: public class StartUp { public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(); ...
Mayank's user avatar
  • 367
0 votes
1 answer
412 views

Automapper - map from List item property to List of int

Using .NET Core with EF and Automapper. How can I map the Property of a List Item to a List of same type as the Property? I'd like to map the int JobId from each Job in Address.JobHistory to the ...
Gary Krause's user avatar
3 votes
1 answer
411 views

How to ignore properties of a specific type when using Automapper?

Let's suppose that I have two types: class Type1 { public int Prop1 { get; set; } public string Prop2 { get; set; } public string Prop3 { get; set; } } class Type2 { public int Prop1 ...
meJustAndrew's user avatar
  • 6,281
0 votes
0 answers
172 views

Prevent Automapper from returning non-empty list for empty source

I have automapper set up like this: Mapper.CreateMap<FieldEntry, FieldEntryModel>() .ForMember(dest => dest.DestOptions, source => source.MapFrom(f => f.Field.Options)); ...
tloflin's user avatar
  • 4,050
0 votes
0 answers
336 views

How do I map a complex nested object to a simple object using Automapper?

I'm trying to consume Event Espresso 4 (EE4) REST API in my Xamarin forms app. The DTO that I receive (as JSON) from EE4 REST API is fairly complicated and I would like to flatten it into my "fairly ...
Noel's user avatar
  • 373
30 votes
3 answers
30k views

Where i should put my DTOs in clean architecture?

Need to implement the clean architecture and struggling with DTO concept. As I understand, i can't use my domain objects in presentation layer (asp mvc) instead i should use DTO or viewmodel. I'm not ...
Emad Ali's user avatar
  • 477
1 vote
1 answer
1k views

Converting source property value to custom destination value using Automapper in C#

I have a Source.foo = 1; and type of Destination.foo is string, and i want to choose myself which value to assign to Destination.foo according to the number i get in Source.foo. Is there is a ...
Squirrel's user avatar
0 votes
0 answers
510 views

Should AutoMapper be used to Map from ViewModel back into Model?

Should AutoMapper be used to take data from ViewModel and save back into a database model? I know the opposite practice is good software practice: to have Automapper to extract database models, and ...
user avatar
0 votes
0 answers
85 views

Automapper: How to map a hierarchy in Dictionary

In my program, I represent dynamic objects by using Dictionary, like this: public class MyObject { public Guid Id { get; set; } public Dictionary<string, object> Values { get; set; } ...
Dmitry Arestov's user avatar
0 votes
1 answer
38 views

Automap value of Key in Ienumerable<T> to flat string[]

I'm receiving data from an API call that I need to flatten. The data is stored in a Ienumerable inside another object. Below is an example of my incoming data format. class Incoming { public ...
Peej's user avatar
  • 3
0 votes
1 answer
125 views

Self referencing list mapping

I have a self referencing list for category and children. Each category has a list of children which are as well categories, but the auto-mapper is only applied for the first level of the model. ...
Hassan Kalach's user avatar
0 votes
2 answers
137 views

Self Referencing list item count from parent to to last child

i have a self referencing list of categories , where each category have list of children and in the same time have a list of items . example category1 (has 3 items, has 1 children subcategory ) ...
Hassan Kalach's user avatar
0 votes
0 answers
145 views

Assert that automapper mapping will not throw at runtime because of type discrepancy?

Supposing I have source type class Source { public string Prop {get; set;} } target type class Target { public long Prop {get;set;} } and I have an AutoMapper mapping from ...
AunAun's user avatar
  • 1,433
3 votes
1 answer
778 views

AutoMapper - how to ignore null fields on the source, while using AutoMapper.Map - sometimes

So we have a situation, where we are mapping from let's say ThingDto: public class ThingDto { public string FirstName { get; set; } public string LastName { get; set; } public Guid? ...
efischency's user avatar
3 votes
1 answer
1k views

AutoMapper skip all members on source that are null

given this mapping _mapper.Map(personDto, person, opt => opt.ConfigureMap() .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null)) ); person before mapping ...
stackoverfloweth's user avatar
1 vote
0 answers
196 views

AutoMapper exclude unwanted profiles

I created a PersonInsertDto which inherits from PersonDto so that I could perform a unique mapping for inserts. So my class looks like public class PersonInsertDto : PersonDto I setup a profile with ...
stackoverfloweth's user avatar
9 votes
1 answer
6k views

ProjectionTo return ArgumentException: Argument types do not match

I try to build, some small chat app, first of all, I tried to fetch the list of created chat rooms, but when I fetch data from DB and try to map this by the Queryable Extensions: IQueariable....
Eduard  M's user avatar
  • 257
7 votes
1 answer
4k views

Pragmattic use of AutoMapper with Google Protocol Buffers 3

I want to use AutoMapper with proto3, but the biggest problem I have is in mapping from a source property that may allow null into a proto that never does. When doing such population manually, one ...
me--'s user avatar
  • 2,078
1 vote
2 answers
5k views

AutoMapper requiring mapping members and constructor

I am brand new to AutoMapper and am just trying to get my head around the best way to do things. I quickly ran into a hairy issue mapping between two simple, but realistic, object models. The first ...
me--'s user avatar
  • 2,078
1 vote
2 answers
3k views

What is the alternative of "ResolveUsing" in AutoMapper.Extensions.Microsoft.DependencyInjection 6.0.0

I am working on .Net core 2.1 with AutoMapper.Extensions.Microsoft.DependencyInjection 6.0.0. This is my mapping configuration : CreateMap<User, UserForListDto>() .ForMember(dest => dest....
Arif's user avatar
  • 6,270
0 votes
3 answers
9k views

How to use Automapper with ASP.NET Core 2.2 API

This is the error I get: System.InvalidOperationException: Unable to resolve service for type 'myBackEnd.Entities.Striper' while attempting to activate 'myBackEnd.Controllers....
Lee9287's user avatar
  • 397
0 votes
1 answer
2k views

Automapper 8 mapping not working properly

I have two model classes, when I try to map different properties of different name by using Automapper ForMember method. It throws an automapper configuration validation exception on the mapping of ...
user3661407's user avatar
0 votes
0 answers
907 views

Clean way to scan for automapper profiles from an assembly

I'm trying to get all automapper profiles from an assembly but it seems to get even those that are from automapper since some derive from the Profile Class. I have a hack that feels dirty. I have to ...
xariez's user avatar
  • 547
0 votes
0 answers
107 views

Xamarin - AutoMapper add profile after Initialize

I have a Xamarin application that uses Automapper but I have lots of profiles. If I try to load all these profiles at the application Init, its take several seconds. I would like to Initialize the ...
Hikari's user avatar
  • 599
0 votes
1 answer
120 views

How to map from wrapped source properties to unwrapped destination

I'm trying to map a source structure where some properties are wrapped inside a NonNull<T> generic type (from GraphQL.Conventions library). In practice, I want to use AutoMapper to map a ...
huysentruitw's user avatar
  • 27.8k
0 votes
0 answers
136 views

How to select from a list and map the another object using Automapper

From the nested Entity list we want to select an object and map it in the Dto object, but when we use the Automapper to filter for object which deleteDate is equal null and map it, for each column ...
reza ghadimimotlagh's user avatar
0 votes
0 answers
27 views

Automapper mapping generic property from ISource => IDest, then specifying remaining mappings

My situation is I must merge the name of a related object to a name property on many different models. Those models have implementations which need their own configurations. What I've tried is: ...
C Bauer's user avatar
  • 5,052
3 votes
2 answers
932 views

AutoMapper - Flattening/Unflattening to list

I want to flatten my entity framework model data to dto for my ASP.NET Core REST Web Service. My entity classes (simplified) look like: public class DeliveryNoteEntity { public string VehicleNo {...
Simon Achmüller's user avatar
0 votes
1 answer
744 views

AutoMapper 8.0.0: How to ignore the map that if property has default value?

I have to class as follows: public class ClassA { public string Item1 { get; set; } // null public string Item2 { get; set; } // "This is not null." public int Item3 { get; set; } // 0 ...
mstfcck's user avatar
  • 721
0 votes
1 answer
340 views

automapper ProjectTo need to convert a nullable<long> into a bool

I have been tasked with looking after a web app that was built using automapper to complete all data transformations. So far, I have managed to get most issues sorted out, but I have one that is ...
gilesrpa's user avatar
  • 1,011
2 votes
2 answers
384 views

Automapper: Flattening by properties naming convention does not work

I want to flatten my data structure to dto. My source class (simplified) looks like: public class DeliveryNote { public DeliveryNoteNested DeliveryNoteNestedInstance { get; set; } public ...
Simon Achmüller's user avatar
1 vote
1 answer
1k views

ReflectionTypeLoadException exception in Asp.Net Core in-memory TestServer

I create a IWebHostBuilder like so: public IWebHostBuilder GetWebHostBuilder() { return new WebHostBuilder().UseContentRoot(_contentRoot) ....
kovac's user avatar
  • 5,269
1 vote
1 answer
2k views

How can I use automapper to map 2 enums that use different casing

I have many enums that I want to keep all caps that I have to map to another system that has no standard at all (caps, no caps, pascal, camel). I can't find an automapper flag to tell it to ignore ...
Shawn Melton's user avatar
1 vote
1 answer
2k views

Is there a way to properly use AutoMapper to implements inheritance with discriminator?

I have a single Model class in my Business Logic, Pet class. In this class I have a discriminator property called Type (int = 1, 2, 3, ...) The final mapping must be Dto of specific derived classes. ...
Marco Scavarda's user avatar
2 votes
1 answer
81 views

AutoMapper failing to convert simple DTO

Currently working through some legacy code, changing from DTOs built manually to using Automapper. All been going fine until I came to this relatively simple class: public class JobRoleCompanyTypeDto ...
Bob Tway's user avatar
  • 9,421
0 votes
0 answers
592 views

Integration testing EF Core + AutoMapper ProjectTo

I'm trying to integration test a service class that uses AutoMapper and the ProjectTo extension method. In the application itself, I am injecting an IMapper via ASP.Net Core's built-in DI framework. ...
Nelson's user avatar
  • 1,729
3 votes
0 answers
53 views

Fabricated "find references" in Visual Studio to understand Automapper config

Are there extension points to add fabricated references into the "find references" feature? Let's say we have two POCO's in different layers in an architecture, these are mapped with AutoMapper. ...
Alex KeySmith's user avatar
1 vote
1 answer
3k views

Automapper unmapped properties error with simple objects mappings

I need to map a model object coming from API to my actual entity object on DbContext. It is used when creating a new machine object using a POST action. As always, I created a simple map for the ...
Cheshire Cat's user avatar
  • 1,951
1 vote
0 answers
69 views

Can't mapping type inherit from List<T>

There are two types inherit List, and I want to use AutoMapper maping it. map result is empty when mapping Type inherit from List class Program { static void Main(string[] args) { ...
Celery Liu's user avatar
0 votes
0 answers
56 views

How to map ExpandoObject (or dynamic) onto instance?

I am having issue with mapping dynamic or ExpandoObject onto instance of the destination type. I know documentation says that no mapping needs to be created upfront to map dynamic type, but what if I ...
epitka's user avatar
  • 17.4k
1 vote
1 answer
788 views

AutoMapper map Dictionary with the help of injected service

I need something like this: public myMappingProfile(IInjectableService myInjectableService) { CreateMap<Source, Destination>() .ForMember(dest => dest....
MatterOfFact's user avatar
  • 1,413
1 vote
1 answer
4k views

Could not create an instance of type . Type is an interface or abstract class and cannot be instantiated

I understand the below solution works fine, however it doesnt seems to be working for collection. Getting "Cannot implicitly convert type System.Collections.Generic.IList<Something> to System....
kijim's user avatar
  • 21
1 vote
0 answers
825 views

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 ...
Teja Swaroop's user avatar
0 votes
0 answers
47 views

Using nested property string with automapper MapFrom

I'd like to use a string that represents some navigation properties on my class for the mapping. I've also tried converting the string to a PropertyExpression but have not been able to wire it up ...
Ciaran O'Neill's user avatar
0 votes
1 answer
1k views

AutoMapper mapping collection to nested objects collection

I am trying to map an object with a collection property to another object with a nested class containing mapped versions of the source collections, but I can't seem to figure out the appropriate ...
Jazzy J's user avatar
  • 312

1
43 44
45
46 47
133