ProjectToType not working well with inheritance
See original GitHub issueHello,
I have a problem using ProjectToType with base-derived class inheritance.
I have a config as follows:
config
.ForType<IPCamera, IpCameraDto>()
.Map(m => m.Image, d => d.AvatarImage)
.Map(m => m.IpAddress, d => d.IPAddress.ToString())
.Include<AxisIPCamera, AxisIpCameraDto>()
.Include<BaslerIPCamera, BaslerIpCameraDto>()
.Include<BaslerGrabberIPCamera, BaslerGrabberIpCameraDto>()
.Include<VirtualIpCamera, VirtualIpCameraDto>();
and I am mapping as follows:
IQueryable<IPCamera> queryable = ...;
queryable.ProjectToType<IPCameraDto>()
The result of map only contains instances of base class dto (IPCameraDto) rather than respective derived types.
When mapping in-memory as follows:
List<IPCamera> cameras = new { .... };
var dtos = _mapper.Map<IPCameraDto>()
The resulting list correctly contains only derived types (AxisIpCameraDto, BaslerIpCameraDto, ...).
Am I doing something wrong? Is this desired behavior? Or is there a bug in ProjectToType method?
Thanks in advance
Issue Analytics
- State:
- Created 4 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
c# - Mapster not mapping
1 Answer 1 · Couple of problems with your solutions: 1. When creating mapper method Register prompts error : Cannot be inferred from...
Read more >Project().To<T>() does not work with inherited types #570
I'm mapping the inherited types as suggested in the tutorial, by mapping each type separately and using . Include on the base type...
Read more >Queryable Extensions
This map through AutoMapper will result in a SELECT N+1 problem, as each child Course will be queried one at a time, unless...
Read more >Problem creating an inheritance map with abstract class.
Is there way to get around this? I have many classes that inherits from Entity and want to avoid creating duplicated maps for...
Read more >Mapping Inheritance
Mapping inheritance serves two functions: Inheriting mapping configuration from a base class or interface configuration; Runtime polymorphic mapping. Inheriting ...
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 Free
Top 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

I also have this behaviour and had expected it differently
Ok thanks for the replies!