Flatten a list which one of its properties is another list of object

前端 未结 3 479
南笙
南笙 2021-01-19 19:26

I have the following classes:

public class Owner
{
    public string Id { get; set; }
    public string Name { get; set; }
}
public class Main
{
    public s         


        
3条回答
  •  滥情空心
    2021-01-19 20:21

    You can do that using linq (secret looping behind the scenes):

    from m in mainList
    from o in m.Owners
    select new FlatList
    {
       Id  = m.Id,
       Name = m.Name,
       OwnerId = o.OwnerId ,
       OwnerName = o.OwnerName 
    };
    

提交回复
热议问题