Skip to content

Retrieving a single row matching search criteria

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

Find a product with the given name

Untyped syntax

var product = await _client
    .For("Products")
    .Filter("ProductName+eq+%27Chai%27")
    .FindEntryAsync();
Assert.Equal("Chai", product["ProductName"]);

Typed syntax

var product = await _client
    .For<Products>()
    .Filter(x => x.ProductName == "Chai")
    .FindEntryAsync();
Assert.Equal("Chai", product.ProductName);

Dynamic syntax

var x = ODataDynamic.Expression;
var product = await _client
    .For(x.Products)
    .Filter(x.ProductName == "Chai")
    .FindEntryAsync();
Assert.Equal("Chai", product.ProductName);

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


Find a product with the given category and supplier

Untyped syntax

var product = await _client
    .For("Products")
    .Filter("CategoryID+eq+1+and+SupplierID+eq+1")
    .FindEntryAsync();
Assert.Equal("Chai", product["ProductName"]);

Typed syntax

var product = await _client
    .For<Products>()
    .Filter(x => x.CategoryID == 1 && x.SupplierID == 1)
    .FindEntryAsync();
Assert.Equal("Chai", product.ProductName);

Dynamic syntax

var x = ODataDynamic.Expression;
var product = await _client
    .For("Products")
    .Filter(x.CategoryID == 1 && x.SupplierID == 1)
    .FindEntryAsync();
Assert.Equal("Chai", product.ProductName);

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


See also:
Retrieving data