Skip to content

Mapping a list of classes to a list of id's #836

Closed Answered by TimothyMakkison
Sune1337 asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry didn't see that your members have different name 😅. You can solve this by adding a MapProperty attribute.

[Mapper]
public static partial class ParentMapper
{
    [MapProperty(nameof(Parent.Children), nameof(ParentDto.ChildIds))]
    public static partial ParentDto MapParent(Parent source);
  
    public static long ChildToLong(Child source) => source.Id;
}

// generates
 public static partial global::ParentDto MapParent(global::Parent source)
{
    var target = new global::ParentDto();
    target.ChildIds = global::System.Linq.Enumerable.Select(source.Children, x => ChildToLong(x));
    return target;
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Sune1337
Comment options

@TimothyMakkison
Comment options

Answer selected by Sune1337
@Sune1337
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants