public class ParentType
{
public int ID;
public string Name;
public List<ChildType> ChildTypes { get; set; }
}
public class ChildType
{
public int ID;
public string Name;
}
public class MixedType
{
public int ParentID;
public string ParentName;
public int ChildID;
public string ChildName;
}
Provided I understand what you are going to do, you have to use this overload of SelectManay extension which allows you to invoke a result selector function on each element therein.
The query should be:
var lst = new List<ParentType>();
var query = lst.SelectMany(p => p.ChildTypes,
(parent, child) => new { parent, child }
)
.Select(p => new MixedType
{
ChildID = p.child.ID,
ChildName = p.child.Name,
ParentID = p.parent.ID,
ParentName = p.parent.Name
});
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With