forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 199
Including standard functions in search criteria
object edited this page Feb 11, 2013
·
14 revisions
OData protocol supports standard functions that can be included in search criteria.
var x = ODataFilter.Expression; var product = client .From("Products") .Filter(x.ProductName.ToLower() == "chai") .FindEntry(); Assert.Equal("Chai", product["ProductName"]);
Request URI: GET Products?$filter=tolower(ProductName)+eq+%27chai%27
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.Length() == 4) .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=length(ProductName)+eq+4
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.StartsWith("Ch") == true) .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=startswith(ProductName%2c%27Ch%27)+eq+true
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.Contains("ai") == true) .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=substringof(%27ai%27%2cProductName)+eq+true
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.Contains("ai") == false) .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=substringof(%27ai%27%2cProductName)+eq+false
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.IndexOf("ai") == 2) .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=indexof(ProductName%2c%27ai%27)+eq+2
Alternative syntax for finding products with the name containing the given string at the specified position
var x = ODataFilter.Expression; var products = client .From("Products") .Filter(x.ProductName.Substring(1) == "hai") .FindEntries(); Assert.NotEmpty(products);
Request URI: GET Products?$filter=substring(ProductName%2c1)+eq+%27hai%27
See also:
Retrieving data
OData URI conventions