Click here to Skip to main content
13,054,329 members (121,913 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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.

Ex:
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
Updated 13-Nov-12 19:42pm
v2

1 solution

Rate this: bad
 
good
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.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2017
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