如何让 IQueryable Item 被字符串列表过滤
How to get an IQueryable Item to be filtered by a list of strings
我正在使用 Odata 作为我的服务来为我的 Kendo 网格获取 class 的 IQueryable。我有一个项目编号字符串列表,我需要过滤我的一个 IQueryable classes 以仅显示该字符串列表中的 class 中的项目编号并将其保留为 IQueryable。
我已经尝试使用 Contains 来过滤掉列表中的项目编号,但我收到错误消息“不支持方法 'Contains'”。我需要将其保留为 IQueryable还有。
以下是我正在使用的代码:
var service = RetailHelper.GetODataItemService();
var query = from a in service.ItemAssortment
where a.Item_Nbr == itemNumber && a.AuditYear == 2018
select a;
var newQuery = query.ToList();
var queryList = newQuery.Select(x => x.Assortment_Nbr.ToString()).Distinct().ToList();
//queryList now has the List of strings that I want to use as the filter
var itemQuery = from a in service.Items
select a;
//I now need to filter itemQuery to only include all the Item Numbers that are in queryList. This is where my dilemma is.
var dsq = RetailerHelper.CreateDataServiceQuery<Item>(itemQuery, request);
//The above is where I will enter in the filtered itemQuery
var qor = dsq.IncludeTotalCount().Execute() as QueryOperationResponse<Item>
var result = new DataSoureResult() { Data = qor.ToList(), Total = Convert.ToInt32(qor.TotalCount) };
return result;
您可以从 queryList
开始而不是 itemQuery
:
var filtered = queryList.SelectMany(x=> itemQuery.Where(item => item.Number == x).ToList());
尝试加入
var itemQuery = from a in service.ItemAssortment
join b in service.Items
on b.Number == a.Assortment_Nbr
where a.Item_Nbr == itemNumber && a.AuditYear == 2018
select b;
我正在使用 Odata 作为我的服务来为我的 Kendo 网格获取 class 的 IQueryable。我有一个项目编号字符串列表,我需要过滤我的一个 IQueryable classes 以仅显示该字符串列表中的 class 中的项目编号并将其保留为 IQueryable。
我已经尝试使用 Contains 来过滤掉列表中的项目编号,但我收到错误消息“不支持方法 'Contains'”。我需要将其保留为 IQueryable还有。
以下是我正在使用的代码:
var service = RetailHelper.GetODataItemService();
var query = from a in service.ItemAssortment
where a.Item_Nbr == itemNumber && a.AuditYear == 2018
select a;
var newQuery = query.ToList();
var queryList = newQuery.Select(x => x.Assortment_Nbr.ToString()).Distinct().ToList();
//queryList now has the List of strings that I want to use as the filter
var itemQuery = from a in service.Items
select a;
//I now need to filter itemQuery to only include all the Item Numbers that are in queryList. This is where my dilemma is.
var dsq = RetailerHelper.CreateDataServiceQuery<Item>(itemQuery, request);
//The above is where I will enter in the filtered itemQuery
var qor = dsq.IncludeTotalCount().Execute() as QueryOperationResponse<Item>
var result = new DataSoureResult() { Data = qor.ToList(), Total = Convert.ToInt32(qor.TotalCount) };
return result;
您可以从 queryList
开始而不是 itemQuery
:
var filtered = queryList.SelectMany(x=> itemQuery.Where(item => item.Number == x).ToList());
尝试加入
var itemQuery = from a in service.ItemAssortment
join b in service.Items
on b.Number == a.Assortment_Nbr
where a.Item_Nbr == itemNumber && a.AuditYear == 2018
select b;