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 Oct 8, 2012
·
14 revisions
OData protocol supports standard functions that can be included in search criteria.
var product = _db.Products.Find(_db.Products.ProductName.ToLower() == "chai"); Assert.Equal("Chai", product.ProductName);
Request URI: Products?$filter=tolower(ProductName)+eq+%27chai%27
var product = _db.Products.Find(_db.Products.ProductName.Length() == 4); Assert.NotEmpty(products);
Request URI: Products?$filter=length(ProductName)+eq+4
var product = _db.Products.Find(_db.Products.ProductName.StartsWith("Ch") == true); Assert.NotEmpty(products);
Request URI: Products?$filter=startswith(ProductName%2c%27Ch%27)+eq+true
var product = _db.Products.Find(_db.Products.ProductName.Contains("ai") == true); Assert.NotEmpty(products);
Request URI: Products?$filter=substringof(%27ai%27%2cProductName)+eq+true
var product = _db.Products.Find(_db.Products.ProductName.Contains("ai") == false); Assert.NotEmpty(products);
Request URI: Products?$filter=substringof(%27ai%27%2cProductName)+eq+false
var product = _db.Products.Find(_db.Products.ProductName.IndexOf("ai") == 2); Assert.NotEmpty(products);
Request URI: Products?$filter=indexof(ProductName%2c%27ai%27)+eq+2
Alternative syntax for finding a product with the name containing the given string at the specified position
var product = _db.Products.Find(_db.Products.ProductName.Substring(1) == "hai"); Assert.NotEmpty(products);
Request URI: Products?$filter=substring(ProductName%2c1)+eq+%27hai%27
See also:
OData URI conventions