从 OData 过滤器查询字符串构建表达式
我有一个 Blazor WASM 应用程序,它构建了一个 $filter url 参数,该参数是使用以下命令生成的:
var dsContext = new DataServiceContext(new Uri("http://stackoverflow.com"));
var query = dsContext.CreateQuery<Product>("/api/products").Where(p => p.Category == "Cars");
因此,如果我使用“query.ToString())
”,我就会返回一个像 ?$filter 这样的 url =Category eq 'Cars'
我使用它发送到我无法控制代码的外部 OData API。
我现在需要做与上面所做的相反的事情,并有一个可以将该 url 查询字符串传递给的函数,它将返回一个相当于 Where(p =>; ) 的
以便我稍后可以在我的 Blazor 应用程序中使用它。我见过的所有示例都需要访问 EdmModel 或我没有的上下文,因为我只是调用 API 并且不知道任何这些信息。我确实有一个 Expression
对象。 p.Category == "Cars")products
类,那么有没有办法将该过滤器查询字符串转换为表达式?
I have a Blazor WASM app that builds a $filter url parameter which is generated using:
var dsContext = new DataServiceContext(new Uri("http://stackoverflow.com"));
var query = dsContext.CreateQuery<Product>("/api/products").Where(p => p.Category == "Cars");
So if I use "query.ToString())
" I then get back a url like ?$filter=Category eq 'Cars'
and I use that to send to an external OData API that I do not have control of the code.
I now need to do the opposite of what I have done above and have a function that I can pass that url querystring to and it will return an Expression
object equivalent to Where(p => p.Category == "Cars")
so that I can use it in later in my Blazor app. All of the examples I have seen require access to an EdmModel or a context which I do not have as I am just calling an API and do not know any of that information. I do have a products
class though so is there anyway to convert that filter querystring into an expression?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论