Skip to content
Jason Finch edited this page Aug 23, 2018 · 3 revisions

Simple.OData.Client supports Any and All functions that can be used to create powerful OData queries.


Find people having at least one trip with budget over 10000

Untyped syntax

var flights = await client
    .For("Person")
    .Filter(any(Trips,Budget gt 10000m))
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.Any(y => y.Budget > 10000d)));

Typed syntax

var flights = await client
    .For<Person>()
    .Filter(x => x.Trips
        .Any(y => y.Budget > 10000d))
    .Expand(x => x.Trips)
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.Any(y => y.Budget > 10000d)));

Dynamic syntax

var x = ODataDynamic.Expression;
IEnumerable<dynamic> flights = await client
    .For(x.Person)
    .Filter(x.Trips
        .Any(x.Budget > 10000d))
    .Expand(x.Trips)
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.Any(y => y.Budget > 10000d)));

Request URI: GET People?$filter=Trips%2Fany%28x1%3Ax1%2FBudget%20gt%2010000.0%29


Find people having all trips with budget over 10000.

Untyped syntax

var flights = await client
    .For("Person")
    .Filter(all(Trips,Budget gt 10000m))
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.All(y => y.Budget > 10000d)));

Typed syntax

var flights = await client
    .For<Person>()
    .Filter(x => x.Trips
        .All(y => y.Budget > 10000d))
    .Expand(x => x.Trips)
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.All(y => y.Budget > 10000d)));

Dynamic syntax

var x = ODataDynamic.Expression;
IEnumerable<dynamic> flights = await client
    .For(x.Person)
    .Filter(x.Trips
        .All(x.Budget > 10000d))
    .Expand(x.Trips)
    .FindEntriesAsync();
Assert.True(flights.All(x => x.Trips.All(y => y.Budget > 10000d)));

Request URI: GET People?$filter=Trips%2Fall%28x1%3Ax1%2FBudget%20gt%2010000.0%29


See also:
Retrieving data
OData URI conventions