简体   繁体   English

OData Linq到查询字符串

[英]OData Linq to Query String

I'm using Web API with OData Query support (nighties) and while I'm aware that the WCF library gives you the ability to query WCF RIA Service URLs what I'm looking for is a lightweight way of generating Odata Query strings sort of like LinqPad does but more generically. 我正在使用带有OData查询支持的Web API(晚安),并且我知道WCF库使您能够查询WCF RIA服务URL,我想要的是一种轻量级的生成Odata查询字符串的方式像LinqPad一样,但更通用。

For instance if we know that a service returns a specific type of say "ProductDTO", I want to be able to do something like this: 例如,如果我们知道服务返回特定类型的“ ProductDTO”,则我希望能够执行以下操作:

(from p in ODataSource<ProductDTO>
 where p.Name == "hi"
 select new {p.Model, Name}).ToODataQuery();

Which would return the appropriate $filter and $select commands as a string that can be appended to the URL. 它将返回适当的$ filter和$ select命令作为可以附加到URL的字符串。

Anyone know of any library that can do something like this? 任何人都知道任何可以做这样的事情的图书馆吗?

Another possiblity would be to use the Simple.OData.Client as outline here: Can this library be used to generate the request url only? 另一个可能性是使用Simple.OData.Client作为此处的概述: 该库只能用于生成请求url吗? .

I haven't used it, but am researching a similar topic, and this looks like it should provide the functionality that you're looking for: https://bitbucket.org/jjrdk/linq2rest/wiki/Home 我没有使用过它,但是正在研究一个类似的主题,它看起来应该可以提供您正在寻找的功能: https : //bitbucket.org/jjrdk/linq2rest/wiki/Home

Here's an article that shows using it as an oData client: http://blog.petegoo.com/index.php/2012/03/11/creating-a-net-queryable-client-for-asp-net-web-api-odata-services/ 这是一篇文章,显示了将其用作oData客户端: http ://blog.petegoo.com/index.php/2012/03/11/creating-a-net-queryable-client-for-asp-net-web- api-odata-services /

Based on the wiki (and not based on any experience with linq2rest), it appears that it goes both ways - LINQ expression to query string, and query string to LINQ expression. 基于Wiki(而不是基于linq2rest的任何经验),似乎它是双向的-LINQ表达式查询字符串,查询字符串到LINQ表达式。

You could try this: https://github.com/ubergeoff/HollowPoint.Azure 您可以尝试以下方法: https : //github.com/ubergeoff/HollowPoint.Azure

ODataSource.Query()
.Where(t => t.Age >= 16 && t.Age < 33)
.ToODataString();   

Would output the OData query text: 将输出OData查询文本:

((Age ge 16) and (Age lt 33))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM