使用linq asp.net获取特定会议标题的决策列表 [英] get list of decision for a specific meetingtitle using linq asp.net
问题描述
嗨!
我有一个Db表。我想要的是使用group by子句获取数据,就像我在下面的代码中使用的那样。
注意Decision是另一个表。现在我希望所有与特定会议标题相关的决定都应该显示在列表中。比如
meetingtitle1 = decision1,decison2,decison3
meetingtitle2 = decision1,decison2
但是代码下方只返回一个决策标题。
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.
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
推荐答案
您可以在选择MeetingAgenda中包含决策表
You can include the Decision table in the select of the MeetingAgenda
var queryResult = from meeting in DB.MeetingAgenda.Include(d => d.Decisions)
where (meeting.x == ??)
select meeting
您需要包括上面代码的System.Data.Entity命名空间。
如果循环遍历queryResult,每个会议都会有一个决策对象集合。
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.
这篇关于使用linq asp.net获取特定会议标题的决策列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!