Retrieving a single row by key

object edited this page Oct 9, 2012 · 8 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. Simple.Data method Get is used for key-based collection lookup.


Lookup a row by single numeric key

var product = _db.Products.Get(1);
Assert.Equal("Chai", product.ProductName);

Request URI: GET Products(1)


Lookup a row by single string key

var customer = _db.Customers.Get("ALFKI");
Assert.Equal("ALFKI", customer.CustomerID);

Request URI: GET Customers(%27ALFKI%27)


Lookup a row by compound key

var orderDetails = _db.OrderDetails.Get(10248, 11);
Assert.Equal(10248, orderDetails.OrderID);

Request URI: GET Order_Details(OrderID%3d1%2cProductID%3d1)


See also:
Retrieving data
Simple.Data documentation for Get