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

Viewed 1728

I have the following classes:

public class Owner
{
    public string Id { get; set; }
    public string Name { get; set; }
}
public class Main
{
    public string Id { get; set; }
    public string Name { get; set; }
    public List<Owner> Owners { get; set; }
}

I want to convert List<Main> to List<FlatList> where FlatList is

public class FlatList
{
        public string Id { get; set; }          // Id from Main
        public string Name { get; set; }        // Name from Main
        public string OwnerId { get; set; }     // Id from each Owner in a Main's Owner
        public string OwnerName { get; set; }   // Name from each Owner in a Main's Owner
}

Unfortunately I haven't been able to figure out the LinQ query to perform this operation.

3 Answers
Related