-
Notifications
You must be signed in to change notification settings - Fork 213
Results projection, paging and ordering
object edited this page Oct 9, 2012
·
7 revisions
Simple.Data OData adapter supports all stanard OData query modifiers that can be used to control number of rows and columns fetched during the request execution.
IEnumerable<dynamic> products = _db.Products.All() .Select(_db.Products.ProductID); Assert.True(products.First().ProductID > 0); Assert.Throws<RuntimeBinderException>(() => products.First().ProductName);
Request URI: GET Products?$select=ProductID
IEnumerable<dynamic> products = _db.Products.All() .Take(1); Assert.Equal(1, products.Count());
Request URI: GET Products?$top=1
IEnumerable<dynamic> products = _db.Products.All() .Skip(1); Assert.Equal(76, products.Count());
Request URI: GET Products?$skip=1
IEnumerable<dynamic> products = _db.Products.All() .Skip(2) .Take(1); Assert.Equal(1, products.Count());
Request URI: GET Products?$skip=2&$top=1
IEnumerable<dynamic> products = _db.Products.All() .OrderBy(_db.Products.ProductName); Assert.Equal("Alice Mutton", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName
IEnumerable<dynamic> products = _db.Products.All() .OrderByDescending(_db.Products.ProductName); Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc
IEnumerable<dynamic> products = _db.Products.All() .OrderByDescending(_db.Products.ProductName) .Select(_db.Products.ProductName); Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc&$select=ProductName
See also:
Retrieving data
Simple.Data documentation for Select
Simple.Data documentation for Order