Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
I have a Db table. what i want is to get data using group by clause as i have used in below code.
Note that Decision is another table. now i want that all the decisions related to a specific Meeting Title should be shown in list.like
meetingtitle1=decision1,decison2,decison3
meetingtitle2=decision1,decison2
but below code returns only one decisiontitle.

C#
public List<NewMeetings> GetAllMeetings()
       {

           var xyz = (from m in DB.MeetingAgenda
                      //join mp in Meeting on m.MeetingId equals mp.MeetingId
                      //where m.MeetingId == 2
                      group m by new { m.Meeting.MeetingTitle } into grp
                      select new NewMeetings
                      {
                          //  meetingid = grp.Key.MeetingId,
                          meetingtitle = grp.Key.MeetingTitle,
                          decision = grp.Select(x => x.Decision.DecisionTitle).FirstOrDefault(),

                          total = grp.Count()
                      }).ToList();

           List<NewMeetings> list = xyz.ToList();
           return list;
         

          
       }

       public class NewMeetings
       {
           public int meetingid;
           public string meetingtitle;
           public string decision;
           public int total;
       }


Can somebody please tell me how to retrun list of decision to a specific Meetingtitle
Thanks in advance
Posted

1 solution

You can include the Decision table in the select of the MeetingAgenda
C#
var queryResult = from meeting in DB.MeetingAgenda.Include(d => d.Decisions)
                  where (meeting.x == ??)
                  select meeting


You need to include the System.Data.Entity namespace for the code above.

If you loop through the queryResult, each meeting will have a collection of decision objects present.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900