✅ AutoMapper - mapping record to a class (.NET 7)
I am using mediatr for my project and I have my command using a sealed record and when I try to map my record to my entity I run into an AutoMapper Extension error.
Error: Exception thrown: 'AutoMapper.AutoMapperMappingException' in AutoMapper.dll
CODE:
When my CreateProductCommand was still a class the mapping worked with no issues.
10 Replies
aren't there more details in the exception?
Unfortunately not. Just that and that's all. But I was able to narrow it down to that it's an issue when I try map a record with a class.
i guess you ould try explicit construction of the record from automapper?
even if just as a test
the problem is that record wants to get propertys through constructor
automapper cant do that by default
you can try ConstructUsing or the other one
Stack Overflow
AutoMapper: Problem with mapping records type
I am mapping with automapper 10.1.1 in c# 9 from this class
public record BFrom
{
public Guid Id { get; init; }
public Guid DbExtraId { get; init; }
}
into this
public record ATo(Guid Id,...
like ForCtorSomething
Would I then have to create a map profile for each and every mapping I will do? Is there a way I can just make it generic to automatically map the properties?
if it doesn't work without
ForCtorParam
that's what you have to do
i've never searched if there is some source generator or whatever that reduces this effortShucks that is gonna be a tedious effort for each and everytime a new record is added and a particular mapping is required.