I’m working on a project that uses the new Web API and I noticed somebody is returning an IQueryable<T> from a Get method.
My understanding is that IQueryable is useful for improving performance (deferred execution), but I don’t think a client on the other end of an HTTP connection is going to be able to take advantage of that.
My gut is telling me that this should be IEnumberable<T>instead. Am I right about this?
Responses to methods returning
IQueryable<T>can be “queried” by passing some odata-like parameters in the query string ($top, $skip, $filter, $orderby). For example, if your resource can be found at …/api/People, you can send those requests, which will cause the server to return different data:Notice that on the beta release any operation which returns
IQueryable<T>automatically has this “querying” support added to it. On the latest bits (from codeplex), you need to manually add a[Queryable]attribute to the operation to enable this behavior.If you don’t want that querying behavior, then yes, returning
IEnumerable<T>is just fine.