-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Unflattening not working even when providing MapProperty #381
Comments
I'm using the PreRelease version 2.8.0-next.2 |
I think the configurations you set are not correct. |
This works. Thanks. |
The same does also work with nameof, you can even use the array ctor of the attribute. |
It's great that the reverse works out of the box Wouldn't it be possible to make a ReverseMapping ? |
Each mapping in Mapperly has it‘s own configuration and os not directly connected to other mapping methods. As Mapperly only generates implementations of user defined partial methods, I can‘t think of an approach which could work. |
So "Unflattening" out of the box is out of question? |
I think so, unless you have a good idea on how this could be solved. |
It could be its own attribute that would generate a similar reversed method. It could try to reverse the mapping stragedy and reverse it, although I don't think there is curretly a way of getting this. Perhaps an analyzer could tell the user to create a reverse map for any user generated mapping functions. It would definetely be a lot of work 😆 [TwoWayMapper]
public static partial void Update(Source source, Target target);
// Generates...
public static partial void Update(Target source, Source target);
I ran into a similar issue when looking at #349 and #103. Mapperly descends down the mapping tree, generating the mappings but does not pass information up to its parent mapping. This way you can't pass parameters down to complex mappings or user mappers that take additional parameters. Mapperly would have to be refactored to depth first descend and work its way back up so that the correct parameters can be passed down. Examples where it could be smarter: // This is the same as [MapProperty(nameof(Car.Manufacturer), nameof(CarDto.Producer))] but Mapperly requires a parameterless constructor with accessible parameters here.
[MapProperty("Manufacturer.Id", "Producer.Id")]
[MapProperty("Manufacturer.Name", "Producer.Name")]
public static partial CarDto MapCarToDto(Car car); // ProducerDto has no accessible parameterless constructor. Ideally it should generate // this would be useful for #109. Not possible mapperly
target.Producer = MapToProducerDto(car.Manufacturer.Id, car.Manufacturer.Name);
// smart mapper
target.Producer = MapToProducerDto(car.Manufacturer); Second Example: [MapProperty("Manufacturer.Id", "Producer.Id")]
[MapProperty(nameof(Car.NumberOfSeats), "Producer.Name")]
public static partial CarDto MapCarToDto(Car car); // ProducerDto has no accessible parameterless constructor. Ideally it should generate target.Producer = MapToProducerDto(car.NumberOfSeats, car.Manufacturer.Name);
// smart mapper
target.Producer = MapToProducerDto(car); |
I Cannot Map Nested Object with unflattening even when I specify the property with the MapPropertyAttribute
My Source Class:
My Target Class:
I would like to Map SourceTimeserie.Id property of the target with SourceTimeserieId Property from the source
SourceTimeserie class:
When I do the inverse Mapping it works perfectly
so this
private static partial void Update(Target target, Source source);
Result:
On the other side:
private static partial void Update(Source source, Target target);
Doesn't map Target.SourceTimeserie.Id
even when I speficy
[MapProperty("Source.SourceCompositionId", "Target.SourceComposition.Id")]
or
[MapProperty(nameof(Source.SourceCompositionId), nameof(Target.SourceComposition.Id))]
Any Idea why the mapping doesn't work?
The text was updated successfully, but these errors were encountered: