Share via


Key lookup in WCF Data Services

Vitek has another great post in his series over at https://blogs.msdn.com/b/vitek/archive/2010/06/16/data-services-expressions-part-6-key-lookup.aspx.

There are a couple of things that I think are worth calling out.

  1. The provider doesn't know if it needs to produce many items or just one. It can figure it out by looking at the expression and see if there's a key filter of course, but generally it doesn't know. This is because the difference between /Customers(1) and /Customers?$filter=ID eq 1 affects the serialization more than anything else, when choosing to return a feed or an entry. The query should behave the same way, so it's only the runtime that keeps track of this information.
  2. Each key value in a compound-key entity is a separate Where operation (mostly) . Logically these can be merged into a single Where operation with an And operator for each equality, and the results should be the same - the provider is free to do that of course. You would get the longer expression if someone queried for /Customers?$partitionid eq 1 and rowid eq 2 instead of /Customers(partitionid=1,rowid=2).

Thankfully, most everyone will work with an existing provider like the ADO.NET Entity Framework, so you'll never have to worry about these details.

Enjoy!