forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 200
Including standard functions in search criteria
JonAdamsFromNC edited this page Jan 30, 2023
·
14 revisions
OData protocol supports standard functions that can be included in search criteria.
var product = await client
.For("Products")
.Filter("tolower(ProductName)+eq+%27chai%27")
.FindEntryAsync();
Assert.Equal("Chai", product["ProductName"]);
var product = await client
.For<Products>()
.Filter(x => x.ProductName.ToLower() == "chai")
.FindEntryAsync();
Assert.Equal("Chai", product.ProductName);
var x = ODataDynamic.Expression;
var product = await client
.For(x.Products)
.Filter(x.ProductName.ToLower() == "chai")
.FindEntryAsync();
Assert.Equal("Chai", product.ProductName);
Request URI: GET Products?$filter=tolower(ProductName)+eq+%27chai%27
var products = await client
.For("Products")
.Filter("length(ProductName)+eq+4")
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For<Products>()
.Filter(x => x.ProductName.Length() == 4)
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.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
var products = await client
.For("Products")
.Filter("startswith(ProductName%2c%27Ch%27)+eq+true")
.FindEntriesAsync();
Assert.NotEmpty(products);
var products = await client
.For<Products>()
.Filter(x => x.ProductName.StartsWith("Ch") == true)
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For(x.Products)
.Filter(x.ProductName.StartsWith("Ch") == true)
.FindEntriesAsync();
Assert.NotEmpty(products);
Request URI: GET Products?$filter=startswith(ProductName%2c%27Ch%27)+eq+true
var products = await client
.For("Products")
.Filter("substringof(%27ai%27%2cProductName)+eq+true")
.FindEntriesAsync();
Assert.NotEmpty(products);
var products = await client
.For<Products>()
.Filter(x => x.ProductName.Contains("ai") == true)
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For(x.Products)
.Filter(x.ProductName.Contains("ai") == true)
.FindEntriesAsync();
Assert.NotEmpty(products);
Request URI: GET Products?$filter=substringof(%27ai%27%2cProductName)+eq+true
var products = await client
.For("Products")
.Filter("substringof(%27ai%27%2cProductName)+eq+false")
.FindEntriesAsync();
Assert.NotEmpty(products);
var products = await client
.For<Products>()
.Filter(x => x.ProductName.Contains("ai") == false)
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For(x.Products)
.Filter(x.ProductName.Contains("ai") == false)
.FindEntriesAsync();
Assert.NotEmpty(products);
Request URI: GET Products?$filter=substringof(%27ai%27%2cProductName)+eq+false
var products = await client
.For("Products")
.Filter("indexof(ProductName%2c%27ai%27)+eq+2")
.FindEntriesAsync();
Assert.NotEmpty(products);
var products = await client
.For<Products>()
.Filter(x => x.ProductName.IndexOf("ai") == 2)
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For(x.Products)
.Filter(x.ProductName.IndexOf("ai") == 2)
.FindEntriesAsync();
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 products = await client
.For("Products")
.Filter("substring(ProductName%2c1)+eq+%27hai%27")
.FindEntriesAsync();
Assert.NotEmpty(products);
var products = await client
.For<Products>()
.Filter(x => x.ProductName.Substring(1) == "hai")
.FindEntriesAsync();
Assert.NotEmpty(products);
var x = ODataDynamic.Expression;
var products = await client
.For(x.Products)
.Filter(x.ProductName.Substring(1) == "hai")
.FindEntriesAsync();
Assert.NotEmpty(products);
Request URI: GET Products?$filter=substring(ProductName%2c1)+eq+%27hai%27
See also:
Retrieving data
OData URI conventions