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.
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:
(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.
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?.
You could try this: https://github.com/ubergeoff/HollowPoint.Azure
ODataSource.Query()
.Where(t => t.Age >= 16 && t.Age < 33)
.ToODataString();
Would output the OData query text:
((Age ge 16) and (Age lt 33))
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
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With