forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 197
Retrieving a single row by key
Jason Finch edited this page Aug 23, 2018
·
15 revisions
Every OData collection must define a key that consists of a single or multiple properties and can be used for entry lookup and addressing links between different OData collections.
var product = await client
.For("Products")
.Key(1)
.FindEntryAsync();
Assert.Equal("Chai", product["ProductName"]);
var product = await client
.For<Products>()
.Key(1)
.FindEntryAsync();
Assert.Equal("Chai", product.ProductName);
var x = ODataDynamic.Expression;
var product = await client
.For(x.Products)
.Key(1)
.FindEntryAsync();
Assert.Equal("Chai", product.ProductName);
Request URI: GET Products(1)
var customer = await client
.For("Customers")
.Key("ALFKI")
.FindEntryAsync();
Assert.Equal("ALFKI", customer["CustomerID"]);
var customer = await client
.For<Customers>()
.Key("ALFKI")
.FindEntryAsync();
Assert.Equal("ALFKI", customer.CustomerID);
var x = ODataDynamic.Expression;
var customer = await client
.For(x.Customers)
.Key("ALFKI")
.FindEntryAsync();
Assert.Equal("ALFKI", customer.CustomerID);
Request URI: GET Customers(%27ALFKI%27)
var orderDetails = await client
.For("OrderDetails")
.Key(10248, 11)
.FindEntryAsync();
Assert.Equal(10248, orderDetails["OrderID"]);
var orderDetails = await client
.For<OrderDetails>()
.Key(10248, 11)
.FindEntryAsync();
Assert.Equal(10248, orderDetails.OrderID);
var x = ODataDynamic.Expression;
var orderDetails = await client
.For(x.OrderDetails)
.Key(10248, 11)
.FindEntryAsync();
Assert.Equal(10248, orderDetails.OrderID);
Request URI: GET OrderDetails(OrderID%3d1%2cProductID%3d1)
See also:
Retrieving data