question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ProjectToType not working well with inheritance

See original GitHub issue

Hello,

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:closed
  • Created 4 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
flobibercommented, May 26, 2023

I also have this behaviour and had expected it differently

0reactions
AzGhortcommented, May 30, 2023

Ok thanks for the replies!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found