How to combine two flat lists into one nested object

后端 未结 4 534
-上瘾入骨i
-上瘾入骨i 2021-01-25 12:25

I have three lists which contains three same properties in each collection. I want to combine a result into one collection. Ex classes structure is as below

publ         


        
4条回答
  •  遇见更好的自我
    2021-01-25 13:22

    You can use inheritance.

    public class ResultCollection : Collection1
    {
        List Collection2s { get; set; }
        List Collection3s { get; set; }
    }
    

    and then

    var result = new ResultCollection {
        PropId1 = Collection1.PropId1,
        PropId2 = Collection1.PropId2,
        ...
        Collection2s = Collection2,
        Collection3s = Collection3
    }
    

    An automapper can be helpful here.
    https://docs.automapper.org/en/stable/

提交回复
热议问题