Extending OData Entity Classes

When adding a service reference to an OData service, the generated entities classes are made partial classes. This provides a useful extensibility point for extending the model, and for providing custom logic within entities themselves.

The EbayModel.Item class, for example, contains a TimeLeft property. This property is provided as a string. If it was of type TimeSpan, however, it would be easier to work with.

This section creates a new partial Item class and, within it, a TimeSpan property that converts the string value provided by the OData service into a TimeSpan value.

The following is an example of the format used by the TimeLeft string:

P0DT0H13M8S

The string contains tokens that indicate value positions ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.