本文整理汇总了C#中IQueryable.Filter方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.Filter方法的具体用法?C# IQueryable.Filter怎么用?C# IQueryable.Filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.Filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetData
public static GridDataModel GetData(IQueryable items, string columns, int page, int count, List<string> filter, string sort, string sortdir)
{
var columnsSplit = columns.Split(',').ToList();
var gridData = new GridDataModel();
//Sorting
if (!string.IsNullOrWhiteSpace(sort))
{
if (string.IsNullOrWhiteSpace(sortdir))
{
sortdir = "asc";
}
items = items.OrderBy(sort + " " + sortdir);
}
//Filtering
if (filter == null)
{
filter = new List<string>();
}
var filteredData = items.Filter(columnsSplit, filter);
gridData.TotalRows = filteredData.Count();
gridData.PageCount = count;
gridData.TotalPages = Convert.ToInt32(Math.Ceiling((double)gridData.TotalRows / (double)gridData.PageCount));
if (page < 1)
{
page = 1;
}
if (page > gridData.TotalPages)
{
page = gridData.TotalPages;
}
gridData.CurrentPage = page;
//Paging
if (gridData.TotalRows > 0)
{
filteredData = filteredData.Skip(count * (page - 1)).Take(count).ToList();
}
foreach (var item in filteredData)
{
gridData.Data.Add(item);
}
return gridData;
}
示例2: FilterOnLanguage
private static IQueryable<SearchResultItem> FilterOnLanguage(IQueryable<SearchResultItem> queryable)
{
queryable = queryable.Filter(item => item.Language == Context.Language.Name);
return queryable;
}