Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# LINQ
Please help me out.
I have a list with multiple columns.
my requirement is to get a list with all the columns group by single column.
class SearchList
   string ComposerName;
   string MemberID;
   string Value1;
   String IteamName;
List<searchlist> sl=new List<searchlist>

above "sl" contains multiple items, from that i want to get MemberID, ComposerName, IteamName group by ComposerName using linq.
pleas suggest me code for this
Posted 13-Nov-12 19:29pm
Edited 13-Nov-12 19:42pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I assume that you have a list of your Class type like
List<SearchList> searchList = new List<SearchList>();
And for getting the desired result set by grouping the data try the below code
var groupedList = from entry in searchList
                  group entry by new { entry.ComposerName } into grouping
                  select new
                      ComposerName = grouping.Key.ComposerName,
                      MemberID = grouping.First().MemberID,
                      Value1 = grouping.First().Value1,
                      IteamName = grouping.First().IteamName,

Hope this helps. Please get back if you have any issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 435
1 Maciej Los 335
2 OriginalGriff 278
3 CHill60 180
4 Sinisa Hajnal 180

Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100