Skip to content

Retrieving data matching search criteria

Jason Finch edited this page Aug 23, 2018 · 9 revisions

Find all products with product category equal to 1

Untyped syntax

var products = await _client
    .For("Products")
    .Filter("CategoryID+eq+1")
    .FindEntriesAsync();
Assert.NotEmpty(products);

Typed syntax

var products = await _client
    .For<Products>()
    .Filter(x => x.CategoryID == 1)
    .FindEntriesAsync();
Assert.NotEmpty(products);

Dynamic syntax

var x = ODataDynamic.Expression;
var products = await _client
    .For(x.Products))
    .Filter(x.CategoryID == 1)
    .FindEntriesAsync();
Assert.NotEmpty(products);

Request URI: GET Products?$filter=CategoryID+eq+1


Find all products with the length of name equal to 4

Untyped syntax

var products = await _client
    .For("Products")
    .Filter("length(ProductName)+eq+4")
    .FindEntriesAsync();
Assert.NotEmpty(products);

Typed syntax

var products = await _client
    .For<Products>()
    .Filter(x => x.ProductName.Length() == 4)
    .FindEntriesAsync();
Assert.NotEmpty(products);

Dynamic syntax

var x = ODataFilter.Expression;
var products = await _client
    .For(x.Products)
    .Filter(x.ProductName.Length() == 4)
    .FindEntriesAsync();
Assert.NotEmpty(products);

Request URI: GET Products?$filter=length(ProductName)+eq+4


Find the count of all products with the given name

Untyped syntax

var x = ODataFilter.Expression;
var count = await _client
    .For("Products")
    .Filter("ProductName+eq+%27Chai%27")
    .Count()
    .FindScalarAsync();
Assert.Equal(1, count);

Typed syntax

var count = await _client
    .For<Products>()
    .Filter(x => x.ProductName == "Chai")
    .Count()
    .FindScalarAsync();
Assert.Equal(1, count);

Dynamic syntax

var x = ODataFilter.Expression;
var count = await _client
    .For(x.Products)
    .Filter(x.ProductName == "Chai")
    .Count()
    .FindScalarAsync();
Assert.Equal(1, count);

Request URI: GET Products/$count?$filter=ProductName+eq+%27Chai%27


Find all products with the given name and return its count together with results

Untyped syntax

Promise<int> count;
var products = await _client
    .For("Products")
    .Filter("ProductName+eq+%27Chai%27")
    .FindEntriesAsync(true, out count);
Assert.NotEmpty(products);
Assert.Equal(1, count);

Typed syntax

var annotations = new ODataFeedAnnotations();
var products = await _client
    .For<Products>()
    .Filter(x => x.ProductName == "Chai")
    .FindEntriesAsync(annotations);
Assert.NotEmpty(products);
Assert.Equal(1, annotations.Count);

Dynamic syntax

Promise<int> count;
var x = ODataFilter.Expression;
var products = await _client
    .For(x.Products)
    .Filter(x.ProductName == "Chai")
    .FindEntriesAsync(true, out count);
Assert.NotEmpty(products);
Assert.Equal(1, count);

Request URI: GET Products?$filter=ProductName+eq+%27Chai%27&$inlinecount=allpages


See also:
Retrieving data

Clone this wiki locally