.Map<IDataReader, FooDto> not mapping custom ForMember
See original GitHub issueAll but one of my DTO members are mapped fine, but the one with a different property name (ForMember) doesn’t get mapped.
I have a DTO class:
public class FooDto
{
...
public string UserId {get; set;}
}
My database record has a string column “Id” that I want to map into FooDto, UserId. My configure includes:
CreateMap<IDataReader, FooDto>()
.ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.GetString(src.GetOrdinal("Id"))));
When I call:
var records = mapper.Map<IDataReader, IEnumerable<FooDto>>(reader);
The records include the value for all properties except the “Id” column. In fact, I can do this and my records are still missing a value:
CreateMap<IDataReader, FooDto>()
.ForMember(dest => dest.UserId, opt => opt.MapFrom(src => "abc")));
I don’t think the ForMember code is being executed at all during the IDataReader mapping. Any ideas?
Using AutoMapper 7.0.1 and AutoMapper.Data 2.0.0.
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (6 by maintainers)
Top Results From Across the Web
Auto mapper mapping of nested object within a collection
I have a class(Question) which contains a nested propertry called "PostedBy" which is a class called "User" and I am trying to map...
Read more >Mapping From IDataReader/IDataRecord with AutoMapper
Now we can use AutoMapper to map the results to instances of our view class: var dataReader = ... // Execute a data...
Read more >Retrieving Data Using a DataReader - ADO.NET
Learn how to retrieve data using a DataReader in ADO.NET with this sample code. DataReader provides an unbuffered stream of data.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know the root cause now. I’ll submit a PR later to fix it. In the meantime you can add
AddMemberConfiguration().AddMember<DataRecordMemberConfiguration>();
to yourProfile
constructor and things should start mapping as expected.I’ve bypassed this issue by adding a mapping on IDataRecord.
I’ve created the projection for the properties with a different name from the db field and it works correctly now