Replies: 1 comment
-
|
Thanks for the suggestion! We currently don't have plans to support conditional mapping. We aim to keep Mapperly focused strictly on object mapping and avoid mixing in business logic or complex runtime state checks. For this specific scenario, the best approach is to ignore the target property in the generated method and handle the condition manually in a wrapper: public void Map(MyUser source, MyUser target)
{
// Map standard properties
MapInternal(source, target);
// Apply specific business logic/conditions
if (string.IsNullOrWhiteSpace(target.UserPrincipalName))
{
target.UserPrincipalName = source.UserPrincipalName;
}
}
// Generate mapping but skip the sensitive property
[MapperIgnoreTarget(nameof(MyUser.UserPrincipalName))]
private partial void MapInternal(MyUser source, MyUser target); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently migrating from AutoMapper to Mapperly.
On AutoMapper I have a mapping setup like this
Since
MyUseris a EF Core entity andUserPrincipalNameis the primary key, I want to avoid replacing it (even casing matters in this case).Is anything similar to this possible? Basically I want to map
UserPrincipalNameonly when the destination is null, and not when a value already exists.Beta Was this translation helpful? Give feedback.
All reactions