-
Notifications
You must be signed in to change notification settings - Fork 199
Results projection, paging and ordering
Simple.OData.Client supports all stanard OData query modifiers that can be used to control number of rows and columns fetched during the request execution.
Untyped syntax
var products = client .For("Products") .Select("ProductID") .FindEntries(); Assert.True(products.First()["ProductID"] > 0); Assert.False(products.First().ContainsKey("ProductName"));
Typed syntax
var products = client .For<Products>() .Select(x => x.ProductID) .FindEntries(); Assert.True(products.First().ProductID > 0);
Dynamic syntax
IEnumerable<dynamic> products = client .For(x.Products) .Select(x.ProductID) .FindEntries(); Assert.True(products.First().ProductID > 0);
Request URI: GET Products?$select=ProductID
Untyped syntax
var products = client .For("Products") .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Typed syntax
var products = client .For<Products>() .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Dynamic syntax
var products = client .For("Products") .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Request URI: GET Products?$top=1
Untyped syntax
var products = client .For("Products") .Skip(1) .FindEntries(); Assert.Equal(76, products.Count());
Typed syntax
var products = client .For<Products>() .Skip(1) .FindEntries(); Assert.Equal(76, products.Count());
Dynamic syntax
var products = client .For(x.Products) .Skip(1) .FindEntries(); Assert.Equal(76, products.Count());
Request URI: GET Products?$skip=1
Untyped syntax
var products = client .For("Products") .Skip(2) .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Typed syntax
var products = client .For<Products>() .Skip(2) .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Dynamic syntax
IEnumerable<dynamic> products = client .For(x.Products) .Skip(2) .Top(1) .FindEntries(); Assert.Equal(1, products.Count());
Request URI: GET Products?$skip=2&$top=1
Untyped syntax
var products = client .For("Products") .OrderBy("ProductName") .FindEntries(); Assert.Equal("Alice Mutton", products.First()["ProductName"]);
Typed syntax
var products = client .For<Products>() .OrderBy(x => x.ProductName) .FindEntries(); Assert.Equal("Alice Mutton", products.First().ProductName);
Dynamic syntax
IEnumerable<dynamic> products = client .For(x.Products) .OrderBy(x.ProductName) .FindEntries(); Assert.Equal("Alice Mutton", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName
Untyped syntax
var products = client .For("Products") .OrderByDescending("ProductName") .FindEntries(); Assert.Equal("Zaanse koeken", products.First()["ProductName"]);
Typed syntax
var products = client .For<Products>() .OrderByDescending(x => x.ProductName) .FindEntries(); Assert.Equal("Zaanse koeken", products.First().ProductName);
Dynamic syntax
IEnumerable<dynamic> products = client .For(x.Products) .OrderByDescending(x.ProductName) .FindEntries(); Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc
Untyped syntax
var products = client .For("Products") .OrderByDescending("ProductName") .Select("ProductName") .FindEntries(); Assert.Equal("Zaanse koeken", products.First()["ProductName"]);
Typed syntax
var products = client .For<Products>() .OrderByDescending(x => x.ProductName) .Select(x => x.ProductName) .FindEntries(); Assert.Equal("Zaanse koeken", products.First().ProductName);
Dynamic syntax
IEnumerable<dynamic> products = client .For(x.Products) .OrderByDescending(x.ProductName) .Select(x.ProductName) .FindEntries(); Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc&$select=ProductName
See also:
Retrieving data