I have this list which has the following value
id, name, List<Tag>
where Tag
has 2 data, TagID
and TagName
Now I want to use linq to select the list with this output
id1, name1, tagid1, tag1
id1, name1, tagid2, tag2
id1, name1, tagid3, tag3
id2, name2, tagid4, tag4
How to do this in linq?
Use SelectMany
:
list.SelectMany(item => item.Tags.Select(tag => new { item.Id, item.Name, tag.Id, tag.Tag }));
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