Sorting OData feeds by their title

Let's say you're browsing the Netflix OData catalog, and you'd like to sort the feed entries by their title. You type https://odata.netflix.com/Catalog/Genres?$orderby=title into your browser, but you get this error message back.

No property 'title' exists in type 'NetflixCatalog.Services.Genre' at position 0.

What went wrong? If you look at the payload for all genres, you'll see the title there. But that's the title ATOM element; if you want to refer to a property of genres, you need to use the property name from the model.

<title type="text">20th Century Period Pieces</title>
<updated>2010-03-24T00:33:27Z</updated>
<author>
  <name />
</author>
<link rel="edit" title="Genre" href="Genres('20th%20Century%20Period%20Pieces')" />
<link
 rel=https://schemas.microsoft.com/ado/2007/08/dataservices/related/CatalogTitles
 type="application/atom+xml;type=feed"
 title="CatalogTitles"
 href="Genres('20th%20Century%20Period%20Pieces')/CatalogTitles" />
<category term="NetflixModel.Genre"
 scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
  <m:properties>
    <d:Name>20th Century Period Pieces</d:Name>
  </m:properties>
</content>

So if you run https://odata.netflix.com/Catalog/Genres?$orderby=Name, the response is successful.

Of course you don't have to look at data to figure this out. If you look at the metadata for the service, exposed at https://odata.netflix.com/Catalog/$metadata, you'll see that the mapping is explicitly defined.

<EntityType Name="Genre">
 <Key>
  <PropertyRef Name="Name" />
 </Key>
 <Property Name="Name" Type="Edm.String"
  Nullable="false" MaxLength="50" Unicode="false"
  FixedLength="false"
  m:FC_TargetPath="SyndicationTitle" />
 <NavigationProperty Name="CatalogTitles"
  Relationship="NetflixModel.CatalogTitleGenres"
  FromRole="Genres" ToRole="CatalogTitles" />
</EntityType>

Enjoy!

Update: added missing error message.