Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 16, 2009 04:36 PM by celldss
Member
3 Points
20 Posts
Jul 15, 2009 09:48 PM|LINK
Here are my objects:
But the compiler throws an error on the foreach: Cannot convert type 'System.Collections.Generic.IEnumerable<string>' to 'string'.
Any insights?
Thanks,
Jason
All-Star
29116 Points
5886 Posts
MVP
Jul 15, 2009 11:20 PM|LINK
Basically, the two selects returns an IEnumerable<IEnumerable<string>> is the issue. You want to use the SelectMany extension method. Check this out: http://msdn.microsoft.com/en-us/library/bb534336.aspx
Jul 16, 2009 04:36 PM|LINK
Worked great. Here is the working code:
apps.SelectMany(x => x.Groups.Select(y => y.Name)).Distinct();
celldss
Member
3 Points
20 Posts
Linq: Query A Nested Collection
Jul 15, 2009 09:48 PM|LINK
Here are my objects:
But the compiler throws an error on the foreach: Cannot convert type 'System.Collections.Generic.IEnumerable<string>' to 'string'.
Any insights?
Thanks,
Jason
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: Linq: Query A Nested Collection
Jul 15, 2009 11:20 PM|LINK
Basically, the two selects returns an IEnumerable<IEnumerable<string>> is the issue. You want to use the SelectMany extension method. Check this out: http://msdn.microsoft.com/en-us/library/bb534336.aspx
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
celldss
Member
3 Points
20 Posts
Re: Linq: Query A Nested Collection
Jul 16, 2009 04:36 PM|LINK
Worked great. Here is the working code:
Thanks for your help.