Closed AzGhort closed 1 year ago
I also have this behaviour and had expected it differently
@AzGhort Try materializing your queryable before calling ProjectToType(). Let me know if the problem is still there :)
Edit: By that, I mean:
var result = queryable.ToList().ProjectToType<IPCameraDto>()
@andrerav thanks for the reply, that works, as it is pretty much the same as the code I posted - eg. mapping "in-memory":
List<IPCamera> cameras = new { .... }; var dtos = _mapper.Map<IPCameraDto>()
Is there a reason why it does not work directly on IQueryable? :)
Thanks again
@AzGhort Difficult to tell without seeing the complete query call chain. There are various issues that can occur depending on how the query expression is built and translated (for example EF Core has some known cases that will lead to issues), as well as using async method when materializing the query.
Ok thanks for the replies!
Hello,
I have a problem using
ProjectToType
with base-derived class inheritance. I have a config as follows:and I am mapping as follows:
The result of map only contains instances of base class dto (
IPCameraDto
) rather than respective derived types. When mapping in-memory as follows: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