3

我有(我认为是 odata 格式)这样的网址:

http://localhost:2282/SSE.Web/History.cshtml?GetData=true&itemId=AKE-00129&pid=1&%24filter=indexof(ItemType%2C%27Attri%27)+ge+0&%24skip=0&%24top=50&%24inlinecount=allpages&_=1325589443808

这里有趣的是 $filter 参数。它的格式为“indexof(ItemType,'Attri') ge 0”

源是一个网格(来自 infragistics 的 iggrid),它在 ItemType 列上使用文本“Attri”进行过滤

我的问题是:映射顶部和跳过参数是微不足道的,但如何进行过滤。我需要解析它并构建自己的 linq,还是有其他方法?

这是我到目前为止的代码:

        var skip = int.Parse(Request["$Skip"]);
    var top = int.Parse(Request["$top"]);
    var filter = Request(["$filter"]);

    var db = Database.Open("SSEConnectionString");

    var entries = db.Query("select * from eHistory order by timestamp desc")
    Json.Write(new { results = entries.Where(????).Skip(skip).Take(top), totalRecCount = entries.Count() }, Response.Output);

谢谢你的帮助!

拉尔西

4

2 回答 2

1

您可以使用以下 NuGet 包来应用过滤器:https ://www.nuget.org/packages/Community.OData.Linq

代码示例将是:

using System.Linq;
using Community.OData.Linq;

// dataSet in this example - any IQuerable<T> 
Sample[] filterResult = dataSet.OData().Filter("Id eq 2 or Name eq 'name3'").ToArray();
于 2018-03-01T18:30:46.783 回答
0

如果您为 igGrid 使用 MVC 包装器,则映射已为您完成。以下是Infragistics jQuery 帮助中的引述:

“当使用 ASP.NET MVC 包装器通过 LINQ (IQueryable) 绑定到服务器端数据时,所有编码在 URL 中的过滤信息都会自动转换为 LINQ 表达式子句(Where 子句),因此您不需要这样做为了过滤数据而进行的任何附加操作。”

于 2012-04-19T20:49:09.563 回答