Understanding ahead of time the caveat that "just because a capability is offered doesn't make it a good idea"...
From the looks of it, OData compliant signatures require you return IQueryable.
FOR EXAMPLE:
[Queryable]
public IQueryable<MyModel> Get()
{
return _repo.GetAll().AsQueryable();
}
However, many articles in the recent and not-so-recent past describe IQueryable as:
MY QUESTION IS:
Do you feel the capabilities of IQueryable and OData outweight the issues above?
In answering, I would expect people to talk about:
...things like that.
BACKGROUND: I ask not only because of the items listed above. But also because OData is being sold to us as an "industry standard" rather than a tool in your toolbox. So, implementing this would fundamentally change the returns for our WebAPI calls (where I currently work). We would have to go from our own IResult return signature (which is very useful) to IQueryable which seems to have issues (but may also end up useful).
IRESULT EXAMPLE:
At minimum, our return signatures would change drastically. And, I'm told WebAPI call implementing OData wont work by changing "C Instance" to "IQueryable Instance" (which makes sense).
public interface IResult<C>
{
[JsonProperty(PropertyName = "hasErrors")]
bool HasErrors { get; }
[JsonProperty(PropertyName = "errors")]
IList<String> Errors { get; }
[JsonProperty(PropertyName = "instance")]
C Instance { get; set; }
}
OData helps you focus on your business logic while building RESTful APIs without having to worry about the various approaches to define request and response headers, status codes, HTTP methods, URL conventions, media types, payload formats, query options, etc.”
There is virtually no contract. A service consumer has no idea how to use the service (for example, what are valid Command arguments, encoding expectations, and so on). The interface errs on the side of being too liberal in what it will accept.
The purpose of OData is to provide a protocol that is based on Representational State Transfer (REST) for create, read, update, and delete (CRUD) operations. OData applies web technologies such as HTTP and JavaScript Object Notation (JSON) to provide access to information from various programs.
REST is an architectural style for exchanging information via the HTTP protocol. The REST standard defines principles that must be adhered to by any REST API. OData builds on top of the REST framework to define best practices for building REST APIs—including the HTTP message format, how to query the API, and more.
Supporting OData querying with Web API doesn't require you to have an IQueryable<T>
. Having an IQueryable<T>
lets you get there faster and with lesser code. IQueryable<T>
has the required abstractions to translate an incoming OData query to a LINQ query. The framework already defines it and there is rich support across various back ends for it like Entityframework, NHibernate, Linq2Objects, RavenDB, Linq2OData etc. So, we decided to have rich support for IQueryable<T>
with web API. Agreed, IQueryable<T>
is a huge interface and exposes a lot more than what is necessary for OData querying. But it is something that comes for free :).
That said, we have good support through ODataQueryOptions<T>
for non-IQueryable case. Check out my blog post about this here
Also, you are confusing OData query semantics with OData. Rich query support is only one part of OData. OData builds on top of HTTP and has various useful features like
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