您要使用的Any()
方法上Category.CategoryItems
Any()
返回true
如果Count > 0
和false
如果Count == 0
// Select only the Categories which have at least one CategoryItem.
IEnumerable<Category> categoriesWithItems = Context.Categories.Select(x => x.CategoryItems.Any());
对于
linqdatasource
要使用
Selecting event handler
。 MSDN。
的ASPX: -
<asp:LinqDataSource ID="LinqDataSource1"
runat="server"
ContextTypeName="MyDataContext"
OnSelecting="LinqDataSource1_Selecting">
</asp:LinqDataSource>
的方法: -
public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = categoriesWithItems = Context.Categories.Select(x => x.CategoryItems.Any());
}
我使用的LinqDataSource在aspx页面,可以用它做什么? –
是的,以下博客文章将为您提供帮助。 http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx –