我拥有的:
1)。我有一个列表框,该列表框代表类别列表
2)。该列表框在其数据模板中还有另一个列表框,它是每个类别 3) 中的板列表
。我使用 RIA 服务从数据库获取数据,并使用 Linq/Lambda 语句进行查询
4)。数据库中的数据来自2个表a)。包含所有类别的类别和 2)。板,其中包含每个类别的所有板。
5)。到目前为止我已经有了这些(在域服务中)
public IQueryable<discussion_category> GetDiscussion_category()
{
return this.ObjectContext.discussion_category;
}
public IQueryable<discussion_board> GetDiscussion_boardsByCategory(int CategoryID)
{
return this.ObjectContext.discussion_boards.Where(e => e.CategoryID == CategoryID);
}
public IQueryable<discussion_board> GetDiscussion_board()
{
return this.ObjectContext.discussion_board;
}
6)。但我希望能够执行以下操作(可能正在使用 join?有人可以帮助我处理这些语句吗?或任何其他想法?)
我想做的事情:
1)。我想获取数据,使 xaml 绑定类似于第一个类别,然后是其板列表,然后是第二个类别及其板列表等。
2)。我希望数据像
Category 1
Board 1
Board 2
Board 3
Category 2
Board 4
Board 5
Board 6
etc
问题:
我如何使用 Linq/lambda 语句实现此目的?
What I have:
1). I have a listbox and this listbox represents list of categories
2). this listbox has an other listbox in its data template which is the list of boards in each category
3). I use RIA services to fetch the data from the Database, and query using Linq/Lambda statements
4). the data in the database comes from 2 tables a). category which has all categories and 2). board which has all boards for each category.
5). I have these so far ( in the Domain Service )
public IQueryable<discussion_category> GetDiscussion_category()
{
return this.ObjectContext.discussion_category;
}
public IQueryable<discussion_board> GetDiscussion_boardsByCategory(int CategoryID)
{
return this.ObjectContext.discussion_boards.Where(e => e.CategoryID == CategoryID);
}
public IQueryable<discussion_board> GetDiscussion_board()
{
return this.ObjectContext.discussion_board;
}
6). but i want to be able to the following, ( may be using join? can someone help me with the statements? or any other idea? )
What I want to do:
1). I want to fetch the data such that the xaml binding will be like 1st category then its list of boards then 2nd category and its list of boards etc.
2). I want the Data to be like
Category 1
Board 1
Board 2
Board 3
Category 2
Board 4
Board 5
Board 6
etc
Question:
How can i achieve this using Linq/lambda statements?
发布评论
评论(2)
您是否尝试过按类别分组?
以下是一些很好的分组示例:
http://msdn.microsoft.com/en-us/vcsharp/aa336754
Have you tried grouping by category?
Here are some good grouping samples:
http://msdn.microsoft.com/en-us/vcsharp/aa336754
您可以在数据模板中设置一个
Dictionary>
,然后将 ListBox 相应地绑定到该字典。为了生成此词典<>,需要执行以下操作:
编辑:您将需要考虑查询延迟。上面是一段通用代码,用于生成您指定的数据结构类型。
编辑:另外,为了使用
Dictionary
,您需要确保 Discussion_category 实现Equals()
和GetHashcode()
You could setup a
Dictionary<Discussion_category, List<Discussion_board>>
In your data template then bind the ListBoxes to this dictionary accordingly. In order to generate this Dictionary<>, something along the following:
Edit: You will need to account for querying delays. The above is a general piece of code, to generate the kind of data structure you indicated.
Edit: Also in order to use
Dictionary<>
you'll need to ensure that Discussion_category implementsEquals()
andGetHashcode()