gpt4 book ai didi

c# - 将 $filter 从 oData 参数映射到 linq Where

转载 作者:行者123 更新时间:2023-11-30 18:40:07 25 4
gpt4 key购买 nike

我有这样的(我认为是一种 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),它在带有文本“Attri”的 ItemType 列上进行过滤

我的问题是:映射 top 和 skip 参数很简单,但是如何进行过滤。我需要解析它并构建我自己的 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);

感谢您的帮助!

拉尔西

最佳答案

您可以使用以下 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();

关于c# - 将 $filter 从 oData 参数映射到 linq Where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8711709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com