Questions tagged [automapper]
A convention-based object-to-object mapper and transformer for .NET
6,577
questions
-3
votes
1
answer
37
views
AutoMapper - Need Help Ignoring Base Class Property [closed]
class BaseA
{ }
class BaseB
{
public string SomeProperty;
}
class DerivedA: BaseA
{ }
class DerivedB: BaseB
{ }
CreateMap<BaseA, BaseB>()
.ForMember(dest => dest.SomeProperty, opt =&...
0
votes
1
answer
82
views
How to map List<Guid> to List<Class> using Automapper?
public class A {
public virtual ICollection<Person> People { get; set; } = new List<Person>();
}
public class B {
public List<Guid> People { get; set; }
}
CreateMap<B, A&...
0
votes
1
answer
45
views
AutoMapper dictionary to class - how to ignore unsupported property mapping?
I'd like to convert dynamic objects of type Dictionary<string, object> to typed classes. Automapper allows that by default without need to create explicit map:
https://docs.automapper.org/en/...
-1
votes
1
answer
116
views
AutoMapper with Custom Type Converter and DI throws AutoMapperMappingException
I'm examining a project which uses AutoMapper and Microsoft.Extensions.DependencyInjection. All
Mappers works as expected, but for one - the only one - which uses a custom type converter.
// there is ...
0
votes
1
answer
52
views
AutoMapper 12.0.1 unit test failing for FindTypeMapFor method
We are updating Auto mapper from 10.1.1 to 12.0.1 in .netcore. After updating we got error for FindTypeMapFor. So I have added using AutoMapper.Internal; namespace. so that issue is resolved but in ...
1
vote
1
answer
97
views
The LINQ expression OrderBy DateTimeOffset.DateTime could not be translated
I have a .NET Core project in which I have implemented this GraphQL query. The query works correctly, but the sorting by date is not working.
[UsePaging(MaxPageSize = 200, IncludeTotalCount = true)]
[...
0
votes
0
answers
42
views
AutoMapper with ConstructUsing to map child properties not valid in test, but works in production
I am trying to test the usage of our AutoMapper profiles in our project. I have an object Source which I map to Destination, actually it has about 30 properties, but for this example it will be fine ...
-1
votes
0
answers
40
views
Missing type map configuration or unsupported mapping. Mapping types: AsyncStateMachineBox`1 -> List`1 - ASP.NET Core 6 Web API
I am getting this error in my ASP.NET Core 6 Web API:
Missing type map configuration or unsupported mapping.
Mapping types:
AsyncStateMachineBox1 -> List1
System.Runtime.CompilerServices....
0
votes
1
answer
43
views
.NET EF Core Automapper ProjectTo filtering is not working
I have the following piece of code
var taskDTOs = await _repo.GetQueryable<TaskStatus>()
.Where(s => s.Tasks.Any(t =>t.CompanyId == _userContext.CompanyId &&
t.UserId == ...
-1
votes
2
answers
82
views
Unable to get Values from Enumeration using Automapper in ASP.NET Core C#
I am using PosgreSQL to return data into my Web API.
I have created my DTO class like below:
public class SuppressionItem
{
public long AccountId { get; set; }
public ...
0
votes
0
answers
40
views
AutoMapper ignores ForMember calls on parameterized constructor construction of an target entity
Because my Issue on Github was closed im opening an thread here.
In my option this is clearly a bug of AutoMappers behavior. Because this directly leads to unexpected errors.
Therefore i directly ...
0
votes
0
answers
30
views
Complext Object Conditional Mapping in AutoMapper
It is my destination object and nested object :
public class Category
{
public int Id { get; set; }
public string CategoryName { get; set; }
public string CategorryDescription { get; set; }...
0
votes
2
answers
105
views
How to use services in a c# AutoMapper Action
I have a profile set up:
builder.Services
.AddAutoMapper((IMapperConfigurationExpression a) => {
a.AddProfile<GeneralMappingProfile>();
});
Here is the Profile:
public class ...
0
votes
2
answers
61
views
Handle circular reference with entity framework or automapper
Im trying to learn and understand how to use entity framework and automapper with relations.
And maby more specifically circular references.
Lets say i have 3 objects:
public class Author
{
public ...
0
votes
1
answer
99
views
C# Automapper and List of parent type not mapping childs
I've tried mapping the children of FirewallRule and when the controller receives the payload, firewallDto is not mapped with the DestinationPorts.
The data is trimmed and the structure is stopping at ...
-1
votes
0
answers
25
views
Operation not supported on iOS for Automapper
I am using automapper to convert a DTO object to another object in Xamarin iOS. I'm receiving reflection errors that aren't supported on iOS. The Dto and target object both have a collection of sub-...
0
votes
1
answer
70
views
.NET 6 and AutoMapper
I'm trying to implement AutoMapper in my project of Hotels in ASP.NET; in .NET 5 it was working fine, but as I moved to .NET 6, I cannot figure out how to exchange this.GetType() in builder.Services....
0
votes
1
answer
41
views
How to add custom Method to ProjectTo in AutoMapper?
I'm using .NET Core 7 and AutoMapper 12 and I'm trying to create a map from an Entity Framework query to a list of DTO's. As I need a list of DTO's, I'm using the .ProjectTo() function from AutoMapper
...
0
votes
0
answers
27
views
how to enable ExplicitExpansion globally
I'm using ProjectTo in AutoMapper and I want to set ExplicitExpansion globally, is there any way to customize it instead of this way?
public class UserDetailResponseProfile : Profile { public ...
-1
votes
0
answers
28
views
Automapper with custom resolver throws error
I would like to convert a WelfareOfficeDto a WelfareOffice.
To do this, it should use my resolver by retrieving the correct WelfareOffice from the database via EfCore using the WelfareOfficeDto.Id and ...
0
votes
0
answers
71
views
In AutoMapper, how can I globally state that I *never* want property to be set in descendant classes?
When calling Services.AddAutoMapper(cfg => how can I specify globally that I never want the Timestamp property to be mapped into on any descendants of my AggregateRoot class?
I have tried the ...
0
votes
1
answer
52
views
AutoMapper bringing data out of nowhere after Entity Framework Query
I'm using .NET Core 7 and Entity Framework Core 7.0.13 and AutoMapper 12.0.3 and I have the following query:
var test = _context.Set<T>
.AsNoTracking()
.Include(m => m....
0
votes
0
answers
52
views
AutoMapper 12.0.1 Update Causes AssertConfigurationIsValid() Failures with Custom Value Resolvers
I have encountered an issue after updating AutoMapper from version 10.0.1 to 12.0.1. The following code is part of my mapping profile, which previously functioned correctly. However, after the update, ...
3
votes
1
answer
62
views
Configure two instance of same type for different constructors in autofac
I'm developing an ASP.NET project using .NET 6, Autofac for dependency injection, and AutoMapper for object mapping. In my project, I have two services, A and B, each of which requires its own ...
0
votes
1
answer
59
views
C# Automapper from flat view model to nested Dto
I'm trying to map a basically flattened view model to a Dto with nested objects. Having a hard time doing it since the view model properties have different names from the Dto. Here's an illustration ...
0
votes
0
answers
50
views
automapper - inject dependency in resolver
One of my fields needs a mapping from a database call hence I am using a resolver that takes a Repository instance to make a database call and return the result.
I am using a Lazy static auto mapper ...
0
votes
2
answers
48
views
Automapper - How get joined table data
i've build example application with .Net Core 7 and trying use Automapper 12.0 and stucked in this situation.
I want to sum values from Table HutangHistory which is joined (maybe) from my ...
0
votes
2
answers
55
views
Setup Automapper member mapping dynamically from a list
I have this source class:
public class MyClass
{
public string Name { get; set; }
public int Height { get; set; }
}
And this destination class (same class, but with properties in another ...
0
votes
1
answer
54
views
AutoMapper throws NullReferenceException with property named 'Original' in mapping source where destination is a record
I am getting NullReferenceExceptions in a mapping where the source type has a property named 'Original' and the destination of the mapping is a record (as opposed to a class). This is with AutoMapper ...
0
votes
0
answers
34
views
What parameter types does ForAllMembers function accept?
I am trying to learn AutoMapper. I have this legacy class which I don't understand how it works. I have researched internet but can't find anything on for example what is op argument passed to ...
-1
votes
1
answer
41
views
What is correct approach to mapping entities to CouchDB documents in a clean architecture? [closed]
I would like to use a Clean Architecture approach in my .NET Core Service - particularly, separate my entities and aggregates from CouchDocument models.
If I understood correctly, then I should do the ...
0
votes
0
answers
87
views
OData, EFCore DTO Error: Expression 'Example.DTOs.Models.ProcessDTO' in the SQL tree does not have a type mapping assigned
What I´m trying to do:
I have an ASP.NET Core project with an ODataController. The ODataController returns DTOs and recevies ODataQueryOptions of type DTO. With Automapper included I can cast my Query ...
0
votes
0
answers
61
views
How to use typescript automapper(nartc/mapper) with Prisma js?
I try to make Prisma work with Automapper (to be able to map Models to Dtos and back). Prisma has schema.prisma where we define models, and that models are generated then automatically for us.. BUT as ...
0
votes
0
answers
42
views
AutoMapper - deserialize dynamic value within collection not working
I'm trying to use automapper in order to fulfill the DTO mapping here, and I have the following situation:
When storing Value into the database, I'm stringifying the JSON attribute using the following:...
0
votes
0
answers
50
views
Problem with AutoMapper version 10.1.1 Cannot create an instance of type
I am using AutoMapper version 10.1.1 with custom converters for my models. I have extension method where I pass in IMapperConfigurationExpression.
public static partial class AutoMapperConfigurator
...
0
votes
1
answer
73
views
Domain object to entity model, EF loses tracking issue (DDD)
I'm trying to follow DDD but feel like I'm missing something. My solution is like:
Domain project having Order and OrderItem classes (these classes have instance methods containing some business ...
0
votes
1
answer
33
views
AutoMapper (v9 & 10) maps successfully when Destination property missing in Source should cause failure
Is this a bug or is there an explanation?
If I understand the AutoMapper documentation correctly, I should be failing when no Source member/mapping is found for Destination member
https://docs....
0
votes
0
answers
69
views
AutoMapper Version="12.0.1" is not working with net7.0 in generic type object
[HttpGet("data")]
public async Task<IEnumerable<SelectItem<int>>> GetDataList()
{
var _record = await _Repo.GetMyRecordDataList().ToListAsync();
//_record record is ...
0
votes
1
answer
81
views
Throw custom error when a mapping error occurs with Automapper in a ASP.NET Core 6 Web API project
I have an ASP.NET Core 6 Web API project and I am using AutoMapper. This is how I am configuring it in my Startup class:
services.AddAutoMapper(Assembly.GetExecutingAssembly());
Is there a way to ...
-1
votes
1
answer
32
views
The error of mapping two classes with auto mapper
I have two classes at the project level, I want to map them with Auto Mapper, but there is a mapping error, can you help me?
public class RegisterVm
{
[Required]
public string FirstName { get; ...
1
vote
1
answer
60
views
How to use a Mock in xunit passing a mapped entity
I'm trying to create an unit test using moq on xunit, but the test is failing, I guest is because of the mapper, when the _sut.Create is called it's thrown an exception, if I remove MockBehavior....
0
votes
1
answer
50
views
Invoke function for each enumarable item while mapping with Automapper
I have 2 classes:
class A
{
public int MyProperty { get; set; }
}
class ADto
{
public int MyProperty { get; set; }
public bool Flag { get; set; }
}
I would like to map IEnumerable to ...
-1
votes
1
answer
54
views
How to map an object inside another object using Automapper?
I'm trying to do the mapping to display a value that is inside an entity, which is inside another entity that is inside another entity, the sequence is "Hose" > "Equipment" > ...
-3
votes
1
answer
188
views
AutoMapper error after upgrading to .NET 7
I upgraded a .NET Core 2.1 app to .NET 7 and upgraded the AutoMapper version that was being used to the latest version.
I had to change the ResolveUsing calls to MapFrom as the earlier was not ...
-1
votes
1
answer
56
views
How to refactor a AutoMapper function in Net Core
I'm resolving a Software Developer entrance exam where I have to develop a Student Enroll courses app, and in one of the stages wherein it requires to write a Mapper function that map a Model with his ...
0
votes
1
answer
68
views
can AutoMapper map to derived/runtime property types from Dictionary<string, object>?
AutoMapper includes support for mapping from a Dictionary<string, object> to an object graph per https://docs.automapper.org/en/stable/Dynamic-and-ExpandoObject-Mapping.html
It also has mapping ...
1
vote
2
answers
90
views
How to make sure that ignoring members in AutoMapper does not set values to null?
I have this code:
var variants = CreateMap<TechDataVariant, TechData>();
variants.ForAllMembers(opt => opt.Ignore());
variants.ForPath(dest => dest.Acceleration.Label, opt => opt....
0
votes
1
answer
52
views
Can't assign null value to a double? property in AutoMapper
I'm using AutoMapper and one line causes an error when I try to assign null in ternary operator like this:
.ForMember(dest => dest.VatCategoryTaxAmount,
opt => opt.MapFrom(src => ...
0
votes
1
answer
74
views
How to map a list of object to a DataTable using AutoMapper
This is my current code.
public class IncidentMapDatatableProfile : Profile
{
public IncidentMapDatatableProfile()
{
CreateMap<FlattenedIncident, DataRow>();
}
}
public ...
-2
votes
1
answer
48
views
Send Email To Admin
I need to send a lot of different forms to the mail. For example FeedBackForm ContactsForm. the only difference is that I create different mail.Subject and mail.Body.
I need to automate this action.
...