Questions tagged [automapper]
A convention-based object-to-object mapper and transformer for .NET
6,158
questions
0
votes
0
answers
24
views
Dependency injection in AutoMapper for custom classes
I am having a Entity and Dto and trying to custom map those classes to have EmpUrl=baseurl+EmpPath.I am planning to get baseurl from configuration file and mapping via DI but getting below error:
...
0
votes
0
answers
15
views
ProjectTo behaves differently than expected when mapping a member via an interface
I discovered some unexpected behavior in my mappings that might be an AutoMapper bug, but there is enough complexity that I might be missing some nuance, somewhere. See this gist for full (minimal) ...
0
votes
0
answers
17
views
Does automapper support mapping collections with circular references?
I'm using automapper to map collections of incoming DTOs objects and save it all at once using Entity Framework. Everything works perfectly fine till I came across part of the database where we have ...
0
votes
1
answer
23
views
Automapper with EnumMapping throws on nullable Enums with unknown value
I have a nullable enum property on the source side and get this property with value 0 instead of NULL.
But 0 is not a represented value in the enum so AutoMapper with ConvertUsingEnumMapping throws an ...
0
votes
1
answer
31
views
Autmapper map collections of different types to collection of another type with nesting
I am currently struggling with automapper.10.1.1 config.
I have following types:
class Response
{
List<Assignment> Assignments { get; }
List<Product> Products { get; }
}
class ...
-2
votes
1
answer
23
views
Automapper profile maps its props to my dto
Hi.
I want just map entity to dto but profile props map to the dto.
Now what can i do for the following problem?
public abstract class DtoProfile<TEntity, TDto> : Profile, IProfile
{
...
0
votes
0
answers
40
views
Collection.AsQueryable() returns NullReferenceException when mapping with AutoMapper
I am still a bit new to programming. I have the following method in my LessonsService:
public async Task<IEnumerable<T>> GetUserLessonsTableDataAsync<T>(string userId, string ...
0
votes
0
answers
44
views
Map from inner property to destination class
I have automapper profile
Here is mappings
CreateMap<CompaniesHouseMatchResult, InputCompaniesHouseSearchResult>()
.ForMember(x => x.CompanyName, opt => opt.MapFrom(aa => aa....
1
vote
2
answers
31
views
How to use AutoMapper to convert Child Object list to either list of strings or list of Guids
I have tried using a custom converted
CreateMap<ChildB, string>().ConvertUsing(src => src.Name);
But I run into the scenario when I want to sometimes get the string like above or sometimes I ...
-1
votes
0
answers
53
views
Slow speed when using AutoMapper in asp.netCore
When the number of source and destination classes is large and we want to define Mapper for them, we will have a large number of Mappers. This wastes a lot of time on the first Request to call Mapper
...
0
votes
0
answers
37
views
Using AutoMapper, how do I set a property based on another table's property?
I am having two tables.
Request table
...
UserId
RequesterId
..
User table
Id
Name
..
I need to map this request model into a ViewModel, adding a "User" and "Requester" string ...
1
vote
0
answers
34
views
how to map list inside class to single object with mapsturct
I want to convert my list inside class to single object.
From :
Class School
private List<SchoolAccount> schoolAccounts;
Class SchoolAccount
private Integer schoolId;
to :
Class SchoolDto
...
0
votes
0
answers
17
views
AutoMapAttribute with ReverseMap & TypeConverter to create 2-way maps?
I have a device I'm communicating with. It returns a number of bitflags in various integer representations (byte, ushort, uint).
Currently, to show them on the UI, they are mapped into ViewModels:
// ...
1
vote
1
answer
34
views
Mapping profile instance doesn't creates
I'm trying to add automapping models with reflection, I created an interface IMapFrom<> and implemented it in all dtos.
Then I created class
public class MappingProfile : Profile
{
public ...
-1
votes
1
answer
23
views
AutoMapper is not including the GetUserDto in response
AutoMapper Class:
namespace ef_practice
{
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Character, GetCharacterDto>();
...
0
votes
0
answers
11
views
How to convert DataTable to List<T> in C#
For convert DataTable to List you can used the AutoMapper Library and you can do it automatically
0
votes
1
answer
29
views
Is there a way to dyanmically create multiple maps for Automapper?
Is there a way to dynamically generate multiple maps? For example, can I map to an array of source and destination values? I am working with a legacy database and one of the tables has over 350+ ...
2
votes
0
answers
39
views
AutoMapper: Prevent Shallow Copy of Self-Mappings
I'm using AutoMapper (version 11.0.1) in a .NET 6 application, and one of its features seems to be that if you map a type to itself, it'll let you do that out of the box.
IMapper mapper = new ...
0
votes
1
answer
58
views
Exception when I try to pass query result to Dto object "Error mapping types"
I am trying to make a basic query to my database with Linq-to-SQL
The query is done correctly, I tried it with LinqPad and it works, the problem (I think so, I'm not an expert) is when trying to pass ...
-1
votes
0
answers
29
views
AutoMapper : "'Object reference not set to an instance of an object" [duplicate]
I'm very new to ASP.NET and AutoMapper,
Basically, I want the data from "websiteowner" to transfer into "model". "model" is of type WebsiteOwnerViewModel and "...
0
votes
0
answers
31
views
Migration of data - SqlException: The MERGE statement conflicted with the FOREIGN KEY constraint
My application is developing and I have come to realize my old data model needed a full remake as it did not force me to add/remove entities from aggregate roots.
Therefore I now need to migrate my ...
0
votes
0
answers
34
views
Automapper and conditional mapping with Record types
to use conditional mapping with automapper , I normally go for a code like this
.ForMember(dest => dest.UpdatedDate, opt =>
{
opt.PreCondition(src => src.UpdatedBy != null);
opt.MapFrom(src ...
0
votes
1
answer
37
views
Entity Framework Automapper pagination IQueryable' doesn't implement 'IAsyncQueryProvider
I have a two entities, AppUser and InterestTag:
public class AppUser : IdentityUser<int>
{
public ICollection<InterestTag> InterestTags { get; set; }
}
public class InterestTag
{
...
0
votes
1
answer
31
views
How to convert IQueryable<IList<AnimeTitle>> to IQueryable<AnimeTitle>
I need to get a collection by id, it has IList<AnimeTitle> AnimeTitles, which I need to convert to IQueryable<AnimeTitle> and project into BriefTitleVW to end up with IQueryable<...
1
vote
1
answer
40
views
Automapper Map from Interface to dynamic while deciding implementation destination based on value
I'm trying to select what the interface will convert to.
So I have the maps set up like this:
CreateMap<ICustomerServiceDto, dynamic>()
.ConvertUsing(service => CreateForServices(...
0
votes
1
answer
56
views
How do I map two objects when one object has no id
problem
I have a dto and a main class with id and I made another dto without id. I don't want the id to be displayed on swagger
Service Layer
public async Task<SuperHeroDto> Create(SuperHeroDto ...
1
vote
1
answer
59
views
Project from a collection to a dictionary
I am trying to use AutoMapper to convert a collection on an entity to a dictionary. This works when I use the Map function, but it is throwing an exception when I use the queryable extension ProjectTo....
0
votes
1
answer
53
views
AutoMapper ProjectTo from a model with child list entity
Is this possible in AutoMapper?
Select list of type X and filter child entity of type Y (return single value of Y)
ProjectTo to a flat DTO contains props from X and Y.
If it is not, then what is the ...
0
votes
2
answers
65
views
Why do I have to Ignore all other properties in AutoMapper when using records?
public record Destination(double X, double Y);
public struct Source
{
public double X { get; set; }
public Potato Potato { get; set; }
public double Z { get; set; }
}
public struct ...
-1
votes
1
answer
58
views
How to use Automapper to project object to Dto in LINQ
I am working on .NET Core 6 along with EF Core. I want to convert Customer and Order object that I have inside LINQ select to CustomerDto and OrderDto using ProjectTo.
Using libraries
using AutoMapper;...
-1
votes
0
answers
29
views
Register & configure AutoMapper profiles to dependency Container
I am working on .NET CORE 6 Web API project and have implemented with clean architecture. I have App.Domain project where I have created Profile classes for autoMapper. In addition I have mapper ...
0
votes
0
answers
27
views
AutoMapper One-To-Many Filter and ProjectTo
I have the below two Entities (one-to-many)
public class ApplicationCode
{
public Guid ApplicationId { get; set; }
public string? ApplicationAcrynom { get; set; }
public int ...
-1
votes
0
answers
38
views
Odata $expand throwing ArgumentException on nested collection property
I am using .Net Core 3.1 with EF Core & Odata Web API. I am trying to return eagerly loaded data as IQueryable mapped with AutoMapper but I get argument exception like below.
System....
0
votes
1
answer
36
views
Create extension method for Automapper AfterMap
I am using Automapper to map data from DbModel to ViewModel. We are saving data in db in UTC timezone. There are few cases when it's fine to display data int UTC and some cases when in Local Timezone.
...
1
vote
1
answer
55
views
Automapper : Ignore Navigation Properties
I've read the 2 proposed answers here and these 2 answers do not match what I want to do as they are manual work. So If I add another navigation property, I would need to modify AutoMapper config.
The ...
-1
votes
0
answers
11
views
AutoMapper get MappingExpression from Mapper or TypeMap
Is it possible to retrieve the MappingExpression from an existing mapper?
The reason for my question is that I'm using AutoMapper in an importing application where certain mappings must be modified ...
0
votes
1
answer
39
views
C# Automapper DTO with nested dto
I want to have a ProductDetailedReadDto with nested CategoryReadDto.
ProductDetailedReadDto:
using System.Collections.Generic;
using Categories.Dtos;
public class ProductDetailedReadDto
{
...
0
votes
0
answers
45
views
Inner properties became null when mapping using ProjectTo<> AutoMapper
I'm new to AutoMapper and its mapping mechanism, I have some models that need to process and query depending on its relationship. For example, I have Tag and Post with 1-to-N relationship.
Post.cs ...
0
votes
1
answer
55
views
Null values after mapping my DTO to my Database Entity
I have a problem when using AutoMapper to map my DTO on a POST Action to my database entity, since my database entity contains multiple references to other database entities, I used also multiple DTOs ...
0
votes
0
answers
24
views
AutoMapper - TypeConverter: Is there any chance to access the destination property from ResolutionContext
Currently I'm working with an Custom Type Converter class which worked good until a new issue appeared. (AutoMapper v11)
My Configuration:
cfg.CreateMap<string, MappedRelatedDataString>()....
0
votes
0
answers
57
views
automapper pass profile as an method parameter
I have columns like this in excel :
ProductID
SomeExplanation
AnotherColumn1
AnotherColumn2
AnotherColumn3
1
X
6
A
65465
2
Y
5
B
6556
3
Z
7
C
65465
I need to convert this excel to list of columns ...
0
votes
0
answers
17
views
How to I set up a many-to-many mapping in AutoMapper for an EF project?
I am really struggling with figuring out how to configure AutoMapper (v10.0.0) for a many-to-many relationship (using .Net Core 3.1/EF Core 3.1.7). I have waded through the AutoMapper documentation, ...
0
votes
1
answer
45
views
Register (for dependency injection) a generic abstract class that imprements a generic interface in Program.cs
I'm trying to create a database with translation tables for multiple languages and in order to have reusable components, I create abstract classes and interfaces for my entities. I have previously ...
2
votes
1
answer
73
views
Automapper ignore all mapping where value is null or default value
I'm using automapper via DI and want to have generic rules for all the mappings found in my solution. Belows example is of a single class, however I've got hundreds of classes to maintain and ...
0
votes
0
answers
46
views
Abp.io AutoMapper extension IgnoreFullAuditedObjectProperties() not working when mapping collection
Using the abp.io framework on their implementation of AutoMapper which is integrated with the framework I'm having some issues mapping collections.
With abp.io our entities have various audited ...
0
votes
0
answers
44
views
C# Automapper conditional mapping of child properties
I know, there are tons of questions related to this topic, but I couldn't find an answer to what I was looking for. All the questions seem to be related to the top level properties, and what I'm ...
0
votes
1
answer
22
views
Use automapper to map entire object to an enum
Is it possible to use automapper to determine an enum for the entire object?
Now I get this error:
Missing type map configuration or unsupported mapping.
When I try like
var orderType = _mapper.Map&...
0
votes
1
answer
54
views
How to use a value resolver when resolving a ctor parameter
I have an entity which has no property setters but has a parameterized constructor:
public class Unit
{
public int Id { get; }
public Player Owner { get; }
public Unit(int id, Player ...
0
votes
0
answers
22
views
Using Automapper in a "plugin" type of component?
I have a site that uses external libraries/dlls that contain services to do various things like retrieve package tracking information. In those libraries I would like to use AutoMapper. Normally I ...
0
votes
2
answers
58
views
Automapper: Avoid mapping source members without destination member to its abstract base class
Question:
I have two classes (source and destination) with dto's which inherit from a abstract base class. When I try to map a list with source members to the destination dto's AutoMapper tries to map ...