I use Microsoft WebAPI with the following NuGet packages installed:
http://nuget.org/packages/Microsoft.Data.OData/
http://nuget.org/packages/microsoft.aspnet.webapi.odata
Which allows me to write things like:
using System.Web.Http; using System.Web.Http.OData.Query; // Some stuff left out [Queryable] public IQueryable<Item> Get(ODataQueryOptions<Item> query) { var items = query.ApplyTo(from item in context.Items select item); return (IQueryable<Item>) items; }
Then I can call it with jQuery Ajax (for example, I prefer using BackboneJS):
$.ajax({ url: '/api/items', data: $.param({ '$filter': 'ID eq 1' }) });
which will then only return elements with an identifier equal to 1, which I think is what you are after?
If ItemID is the main identifier of the object you are retrieving, I will probably follow REST principles and create an API, where the URL to get the item with identifier 1 will look like this:
/api/items/1
And use only oData queries in the collection of elements if I requested based on other properties of the elements of the collection, or do something like below, for example, when extracting the top 10 records.
$.ajax({ url: '/api/items', data: $.param({ '$top': 10 }) });
source share