4

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?

1 Answer 1

8

Use SelectMany:

list.SelectMany(item => item.Tags.Select(tag => new { item.Id, item.Name, tag.Id, tag.Tag }));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.