Using Automapper to map a property of a collection to an array of primitives

前端 未结 1 847
不知归路
不知归路 2021-02-05 21:20

Given the following set of classes:

class Parent
{
    string Name { get; set; }
    List children { get; set; }
}
class Child
{
     short ChildId          


        
相关标签:
1条回答
  • 2021-02-05 21:32

    Use a LINQ query to grab just the ChildIds:

    .ForMember(d => d.ChildIds, o => o.MapFrom(s => s.Children.Select(c => c.ChildId).ToArray()));
    
    0 讨论(0)
提交回复
热议问题