Skip to content

Getting started with Simple.OData.Client

Vagif Abilov edited this page Jul 17, 2014 · 37 revisions

The easiest way to start using Simple.OData.Client is to install it’s Nuget package. In Visual Studio open Package Manager console and type the following:

Install-Package Simple.OData.Client

You will see output similar to this:

Successfully installed 'Simple.OData.Client 3.0.0'.
Successfully added 'Simple.OData.Client 3.0.0' to SimpleODataTest.

In the source file where you will be using OData provider import namespaces:

using Simple.OData.Client;

Create an instance of ODataClient by passing an OData service URL:

var client = new ODataClient("http://packages.nuget.org/v1/FeedService.svc/");

Now you can access data from the OData server using either basic or fluent API.
Example of basic API syntax:

var packages = await client.FindEntriesAsync("Packages?$filter=Title eq 'Simple.OData.Client'");
foreach (var package in packages)
{
    Console.WriteLine(package["Title"]);
}

Example of fluent API syntax:

var packages = await client
    .For("Packages")
    .Filter(x.Title == "Simple.OData.Client")
    .FindEntriesAsync();
foreach (var package in packages)
{
    Console.WriteLine(package["Title"]);
}

See also:
Simple.OData.Client basic API
Simple.OData.Client fluent API
Retrieving data
Modifying data