-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
IQueryable doesn't work with non parameterless ctors #972
Comments
Thanks for opening this issue. I'm not sure if I get all of it correctly, can you perhaps create a minimal replication repository on GitHub? You mention a nullable constructor parameter works around the issue; are all (the mapper, entity, dto and value object) in the same nullability context? The related issues you listed were for types for which Mapperly couldn't generate an automatic mapping implementation at the time, but these are not related to nullability. |
Closing as no update is received, feel free to reopen... |
Here we have a minimal reproduction repo. What is worth noting, removing "ProjectToDto" method makes it all work alright, so the problem must be related to the IQueryable. https://github.com/pawel-pajak-espeo/MapperlyNullableProblemMinimalSetup |
@latonz Can you reopen the issue? @pawel-pajak-espeo cooperates with me regarding this problem because we're working in the same codebase where the problem was discovered. |
Thanks for the repo 👍 Looks like the error Not sure why this happens, especially when the generated code looks fine, here's my guess: In return System.Linq.Queryable.Select(form, x => new Dto(x.InnerRecord ?? new InnerRecord())); As The non I'm not sure if this is a bug or expected behaviour. |
@TimothyMakkison that makes sense. For me it seems like bug. How can I reopen this issue? |
Yeah, It feels super unintuitive.
I think dont think github lets people reopen issues. You'll have to wait for @latonz or one of the Riok guys to reopen this.
Thanks for mentioning this, it has the same cause but I think it can be fixed. I'll look into adding a special case where |
Thanks for the repro, the bugfix is on the way and should land in the upcoming |
@TimothyMakkison You mention a problem with `List', I couldn't find anything about it. Can you elaborate on what the problem is? If you have the time, I'd also appreciate a review on the PR 😊 |
Iirc something like the following would emit a parameterless constructor error. public record Source(List<string> Values);
public record Target(IList<string> Values);
....
public static partial IQueryable<Target>Map(IQueryable<Source> src); It would work fine with
Sure! 😊 |
Describe the bug
It's impossible to generate mapping for
IQueryable<T>
when there is a non nullable, non parameterless ctor type in mapped object.Project with such code has compilation error.
Error in such case is:
Error RMG002 : {SomeType} has no accessible parameterless constructor
.To Reproduce
Steps to reproduce the behavior:
public record ValueObject(string Value);
public record TestDto(ValueObject ValueObject);
IQueryable<T>
mapperExpected behavior
SelectDto
should properly perform mapping when usedCode snippets
Generated mapping seems to be fine:
Environment (please complete the following information):
Additional context
I found a workaround for the problem. It works when we make the type in dto nullable.
So instead of this:
public record TestDto(ValueObject ValueObject);
Make this:
public record TestDto(ValueObject? ValueObject);
I'm very much into DDD and always choose tooling that gives ability to preserve fundamental concepts of DDD.
All above is just example but in real cases I'm implementing I don't want to introduce false statement that something is
nullable
when in real domain it isn't and should be always there.Also I would appreciate if somebody could explain me why such error ever happen? What internally leads to the necessity of having parameterless ctors on things when the actual generated code even doesn't need this?
There are more issues related with this (see below) and also I wasn't able to generate mappings for common stuff like
IReadOnlyList
,IReadOnlyDictionary
with sameno accessible parameterless constructor
error but I don't elaborate on this since somehow I believe the reasoning behind could be same for all cases. But still it's strange for me I can't do it for example for list when below you can see similar issue exactly related to list interfaces that has been closed. I want to better understand internals or maybe there is some common factor across these issues that can be fundamentally solved in design?Related issues
The text was updated successfully, but these errors were encountered: