forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 200
Results projection, paging and ordering
Jason Finch edited this page Aug 23, 2018
·
13 revisions
Simple.OData.Client supports all standard OData query modifiers that can be used to control number of rows and columns fetched during the request execution.
var products = await client
.For("Products")
.Select("ProductID")
.FindEntriesAsync();
Assert.True(products.First()["ProductID"] > 0);
Assert.False(products.First().ContainsKey("ProductName"));
var products = await client
.For<Products>()
.Select(x => x.ProductID)
.FindEntriesAsync();
Assert.True(products.First().ProductID > 0);
IEnumerable<dynamic> products = await client
.For(x.Products)
.Select(x.ProductID)
.FindEntriesAsync();
Assert.True(products.First().ProductID > 0);
Request URI: GET Products?$select=ProductID
var products = await client
.For("Products")
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
var products = await client
.For<Products>()
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
var products = await client
.For("Products")
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
Request URI: GET Products?$top=1
var products = await client
.For("Products")
.Skip(1)
.FindEntriesAsync();
Assert.Equal(76, products.Count());
var products = await client
.For<Products>()
.Skip(1)
.FindEntriesAsync();
Assert.Equal(76, products.Count());
var products = await client
.For(x.Products)
.Skip(1)
.FindEntriesAsync();
Assert.Equal(76, products.Count());
Request URI: GET Products?$skip=1
var products = await client
.For("Products")
.Skip(2)
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
var products = await client
.For<Products>()
.Skip(2)
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
IEnumerable<dynamic> products = await client
.For(x.Products)
.Skip(2)
.Top(1)
.FindEntriesAsync();
Assert.Equal(1, products.Count());
Request URI: GET Products?$skip=2&$top=1
var products = await client
.For("Products")
.OrderBy("ProductName")
.FindEntriesAsync();
Assert.Equal("Alice Mutton", products.First()["ProductName"]);
var products = await client
.For<Products>()
.OrderBy(x => x.ProductName)
.FindEntriesAsync();
Assert.Equal("Alice Mutton", products.First().ProductName);
IEnumerable<dynamic> products = await client
.For(x.Products)
.OrderBy(x.ProductName)
.FindEntriesAsync();
Assert.Equal("Alice Mutton", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName
var products = await client
.For("Products")
.OrderByDescending("ProductName")
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First()["ProductName"]);
var products = await client
.For<Products>()
.OrderByDescending(x => x.ProductName)
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First().ProductName);
IEnumerable<dynamic> products = await client
.For(x.Products)
.OrderByDescending(x.ProductName)
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc
var products = await client
.For("Products")
.OrderByDescending("ProductName")
.Select("ProductName")
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First()["ProductName"]);
var products = await client
.For<Products>()
.OrderByDescending(x => x.ProductName)
.Select(x => x.ProductName)
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First().ProductName);
IEnumerable<dynamic> products = await client
.For(x.Products)
.OrderByDescending(x.ProductName)
.Select(x.ProductName)
.FindEntriesAsync();
Assert.Equal("Zaanse koeken", products.First().ProductName);
Request URI: GET Products?$orderby=ProductName%20desc&$select=ProductName
See also:
Retrieving data