6,649 questions
0
votes
1
answer
218
views
What’s the most efficient way to map large entity models to DTOs in ASP.NET Core without using AutoMapper? [closed]
I'm working on a high-performance ASP.NET Core Web API where each request can return hundreds of entity records. Each entity includes multiple navigation properties and nested objects.
Currently, I’m ...
2
votes
1
answer
128
views
.NET / EF Core / AutoMapper causing PostgreSQL "invalid input syntax for type json" error when saving entity
I'm working on a .NET 8 project using Microsoft.EntityFrameworkCore 8.0.7 with PostgreSQL as the database. I have a table that contains a jsonb column, and I'm using AutoMapper to map a DTO to the ...
1
vote
1
answer
552
views
How to correctly configure the MapperConfiguration?
private readonly IMapper _mapper;
public CreateDepartmentRequestHandlerTests()
{
var config = new MapperConfiguration(cfg => cfg.AddProfile(new CreateDepartmentProfile()));
_mapper = ...
3
votes
1
answer
2k
views
AutoMapper error: MapperConfiguration does not contain constructor that takes 1 arguments
I am getting an error
Error: CS1729 MapperConfiguration does not contain constructor that takes 1 arguments.
from this code:
var config = new MapperConfiguration(
options =>
{
...
0
votes
1
answer
74
views
Automapper. ForAllMembers except some members
I'm using automapper 13.0.1 to map one object to another:
CreateMap<CandidateInfoContactDataSendEvent, TechUser>()
.ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src....
3
votes
2
answers
1k
views
ASP.NET cannot add AutoMapper service
I installed AutoMapper
<PackageReference Include="AutoMapper" Version="15.0.1" />
and created my profile (AutoMapperConfigurationProfile.cs):
using AutoMapper;
using ...
3
votes
2
answers
1k
views
Missing overload AddAutoMapper(params Assembly[]) in v15 — broke manual registration [closed]
Problem Description
After upgrading to AutoMapper v15.0.1, I encountered the following compile-time error when trying to register AutoMapper manually:
services.AddAutoMapper(typeof(AssemblyReference)....
0
votes
1
answer
117
views
Automapper maps properties with the same name automatically despite the fact that I explicitly ignore them [closed]
Despite the fact that I explicitly ignore some props - Automapper maps them because source and destination objects have props with the same name (it is known Automapper behaviour).
Logic is usual:
...
1
vote
1
answer
129
views
How to map two properties into a property which is a single array?
I have two models:
public class HouseDto
{
public DateTime[] ProductionDates { get; set; }
}
and
public class House
{
public string PeriodStart { get; set; }
public string PeriodEnd ...
0
votes
1
answer
112
views
Automapper with interface as target
I have a scenario where data is mapped using Automapper into some target object.
The logic, that runs this mapping should be tested with unit tests.
Since the target object are quite complex and ...
0
votes
0
answers
87
views
TargetInvocationException when resolving IMapper on Android Release build in .Net MAUI
I use Automapper (v.14) in my .Net MAUI (v.9) app.
I configure it as per documentation:
mauiAppBuilder.Services.AddAutoMapper(typeof(MappingProfile));
Then I am trying to resolve IMapper object in ...
0
votes
1
answer
109
views
Conditional map "null" of non-nullable types, enums, and collections with AutoMapper in C#
I'm developing a PATCH REST endpoint to do partial update to an EF Core entity. All properties in the request DTO (EntityRequestDto) are marked as nullable, while the actual entity (Entity) will be ...
-1
votes
1
answer
80
views
MapFrom and ProjectTo fail to populate target property
Given the following EF Core entity class:
[PrimaryKey(nameof(CustomerID))]
[Table(nameof(Customer))]
public partial class Customer
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
...
0
votes
2
answers
211
views
Using DTOs with Polymorphic Models in .NET Core
I am using JsonDerivedType for polymorphic models in .NET Core, and I need to map a hierarchy of complex model objects to a set of DTO objects for serialization. Specifically, I want to use DTOs with ...
3
votes
2
answers
138
views
C# AutoMapper loses custom HashSet comparer when mapping to an init-only property
I'm experiencing an issue where AutoMapper appears to lose a custom comparer when mapping a HashSet property. I have a DTO that contains a collection of strings and a destination model that expects an ...
1
vote
2
answers
123
views
How to Configure AutoMapper to Globally Ignore Specific Properties During Mapping
In my C# project, I frequently use AutoMapper to map between entities and their corresponding Data Transfer Objects (DTOs). Certain properties, such as SecretValue, should consistently be excluded ...
0
votes
1
answer
71
views
Automapper doesn't convert objects correctly with nested type with same propertie's names
I'm trying to map an object of type A with nested object of type NestedType to an object of type B using AutoMapper, but I've encountered some challenges:
If we have same name for:
propertie with ...
1
vote
1
answer
35
views
Using automapper with dynamic linq and order by clause
I'm using automapper for a dynamic query and it's working well until I use an orderby clause.
So this is how I create the query:
IQueryable<DTOFormCellSouches> query;
//Configuration de l'...
0
votes
0
answers
70
views
Is it possible to count element in list with AutoMapper?
I'm using AutoMapper and I'm wondering if it's possible to count elements in a list. I have List elements and the AutoMapper handle maps each element of that list from the source to the Dest object, ...
0
votes
0
answers
40
views
How to Ignore Missing Properties in AutoMapper During Update Requests? [duplicate]
I'm working on an update feature for my ShopOffer class. When updating, I want to ignore properties that are not included in the update request (i.e., the ones that are null). However, some properties ...
0
votes
1
answer
96
views
Non-generic type to open-generic type
I need a way to map a non-generic type into a generic type for deserialization using IValueResolver or IMemberValueResolver
I found this documentation that forwards to github tests.
The problem is ...
0
votes
2
answers
416
views
EF Core throws a tracking exception when updating entities using AutoMapper
I'm using EF Core against a SQL Server database in a Blazor web app (on .NET 9) with Identity, and I am using AutoMapper to convert between the database entities and the DTOs that get sent out of and ...
0
votes
1
answer
52
views
Why is AutoMapper adding a new entity when the Id is null?
My database context has a User model and a Company model. Users can be admin, in which case they aren't associated with a company, or they can be one of two other types, in which case they will be ...
0
votes
1
answer
104
views
How can I pass parameter to AutoMapper profile?
For each row in parent table I have many child rows in child table. But child row is unique for each parent row with "JointId" and "NdtId" and when i call "...
2
votes
2
answers
192
views
How to make Automapper deal with not found input properties?
I have two classes: CustomerLocation and UILocation. Both have a property, called Product but in both cases the type of that Products are different.
I'm performing following piece of source code and I ...
0
votes
2
answers
95
views
DateTime.ToString with Format does not work in AutoMapper
My handler get all Appointments:
public async Task<Result<PagedResult<Responses.AppointmentResponse>>> Handle(Query.GetAppointmentQuery request, CancellationToken cancellationToken)
{...
1
vote
1
answer
81
views
How to skip/set to null Properties in AutoMapper
I'm using Automapper for C# to map an xml object received through an API to a C# model.
The xml received may or may not have the same attributes compared to other xml data received through the same ...
1
vote
0
answers
288
views
AutoMapper 13 is not compatible with .NET 6.0 even though it is compatible with .NET 6.0
I didn't know when this problem starts to occur, but a few weeks back the AutoMapper package that I download from NuGet works fine, but now, when I try to install Automapper 13.0.1 with always prompt ...
0
votes
1
answer
90
views
How to avoid code duplication between DTOs when one extends another with an ID property and a relationship model that's a bit different
I have a domain entity KycInformation and I'm using two DTOs to handle different scenarios:
KycInformationDto for create operations (no ID needed)
KycInformationDetailDto for get/update operations (...
-1
votes
1
answer
79
views
Automapper not mapping null value
I'm trying to map a nullable property, but the automapper indicates an error in this mapping.
Property: HomeTown
Source: Person.NaturalPerson.HomeTown
Destination: PersonDTO.NaturalPersonDTO.HomeTown
...
1
vote
0
answers
45
views
Cannot convert between Data entity and Domain entity IQueryable with Automapper for OData endpoint
I am trying to convert my data entity IQueryable to domain entity IQueryable in my repository class. The Find() method is used by OData to apply filters. The problem is, when I send an OData query ...
0
votes
1
answer
172
views
hot chocolate and automapper could not be translated when model contains collection
I have a resolver that returns an IQueryable from Entity Framework Core. When I return the EF Core entity directly, everything works fine. However, when I attempt to map the EF Core entity to my ...
0
votes
0
answers
38
views
How to set different behavior in AutoMapper when creating a new entity, and doing a partial update?
I'm using Asp.Net with AutoMapper.
Say for example I have a User and a UserDto
public class User
{
public string Id { get; set; } = default!;
public DateTime CreatedAt { get; ...
3
votes
1
answer
186
views
Fill properties based on condition of specific properties
I have the following scenario with the classes:
public class ApiRequest
{
public int? FwVersion { get; set; }
public int? OsVersion { get; set; }
public int PageSize { get; set; }
...
0
votes
0
answers
52
views
How to make a custom C# Automapper for a groupBy LINQ query
I am new to using the AutoMapper library for my specific use case.
The data flows from stored procedure model in repository to service where it gets mapped to a dto to return to the frontend.
This is ...
-1
votes
1
answer
123
views
AutoMapper DTO Not Serializing Correctly for Derived Class Insertion
I'm facing an issue with inserting a derived type of alert in my application. I have a base class, Alert, and its corresponding DTO, along with a derived class, OperationalAlert, which extends Alert, ...
0
votes
2
answers
84
views
Apply in Automapper a Condition over Multiple Map Expressions Without Repetition
I need to apply the following condition ForAllMembers(o => o.Condition((src, dest, srcMember) => srcMember != null)) over multiple map expressions.
My objective is to have an object overriding ...
0
votes
0
answers
432
views
Is there a way to make Automapper work in AOT build/release?
We use automapper.data in our project and it works quite well. Now I am experimenting the idea of publishing our project in AOT mode, After adding these in our project file and run our code
<...
-1
votes
1
answer
65
views
Mapping from type object to a custom class using AutoMapper 6.1.1 in .NET 4.6.2
My class XmlOrder contains the two properties
public class XmlOrder
{
public OrderType OrderType { get; set; }
public object Item { get; set; }
}
If OrderType equals OrderType.Service, Item ...
2
votes
1
answer
81
views
Automapper configuration to map base dictionary values and members as normal
I have the following classes.
public class FieldValue
{
public string Field { get; set; }
public object Value { get; set; }
}
public class FieldValues
{
public FieldValue[] Values { get; ...
2
votes
1
answer
107
views
AutoMapper - Map from list of objects to class with booleans
I am looking to map from the list of objects to a class with booleans. I have the following structure from the source:
public partial class HomeInfoBuilding : object, System.ComponentModel....
0
votes
1
answer
526
views
Directory.Build.props not working to ignore Nuget request to update package
I have a .Net48 solution and I use AutoMapper 10.1.1 in a project. AutoMapper 10.1.1 is the last update that supports .Net48.
I have created a Directory.Build.props file in the solution directory ...
0
votes
1
answer
130
views
Issue with Tuple Mapping Using AutoMapper
Source/destination types
// Source
public record AuthorRequest(
string Name,
string Biography,
DateTime DateOfBirth);
// Destination
public record AuthorUpdateCommand(
Guid Id,
...
-1
votes
2
answers
712
views
How to map and save a model to an entity using Automapper in Entity Framework Core [duplicate]
I have this EmployeeEntity class which is part of my database context.
public class EmployeeEntity
{
public int Id { get; set; }
public string FirstName { get; set; }
//more properties
}...
1
vote
2
answers
83
views
Using Automapper to Map M:M Relationships in EF Core
I have the following two classes:
public class ADto
{
public int Id { get; set; }
public List<BDto>? BSet { get; set; }
}
public class A
{
public int Id { get; set; }
public ...
0
votes
1
answer
113
views
How to project from `Dictionary<A, B>` to `Dictionary<A,C>` with AutoMapper?
I have a fairly simple AutoMapper setup where I want to map IDictionary<Guid, From> to Dictionary<Guid, To>. This works fine with IMapper.Map, but what I really want to do is use ...
-1
votes
1
answer
210
views
Problem with injecting AutoMapper in ASP.NET Core. ERROR: The public parameterized constructor must contain only parameters that match the declared
I have an ASP.NET Core Web API project. In order to configure AutoMapper, I added the following code in my Program.cs file:
builder.Services.AddAutoMapper(typeof(Program));
I inject AutoMapper in my ...
0
votes
0
answers
54
views
AutoMapper.Extensions.OData wrong SQL query for compare nullable DateTime and DateOnly
For all OData endpoints in my ASP.NET Core Web API, I return value in this way:
{
"@odata.context": "...",
"@odata.count": 0,
"value": [...]
}
When ...
1
vote
1
answer
160
views
Problem with AutoMapper in ABP Can not map from given object
I am developing an ABP application with .net core 8.
I have an entity Member as
public class Member: AuditedAggregateRoot<Guid>
{
public string MembershipNo { get; set; }
public ...
-1
votes
1
answer
85
views
Migrate automapper 8 to 13 with custom resolver implemenation
I have custom resolver for automapper written with automapper 8, after moving to 13 I started noticing below error.
How to fix this ? where to look for getting existing mapping inside customer ...