SingleResult<T> not serializable in Web API when querying by key

asp.net-web-api, asp.net-web-api-odata, odata, wcf-data-services

Solution

The web.api controller method by default was not queriable, thus client failed. Added annotation to fix: `[Queryable(AllowedOrderByProperties = "Id")]`

Problem

Trying to find single record using primary key CourseID against odata web.api using this: ``` var editedcourse = container.Courses.Where(c => c.CourseID == ID).SingleOrDefault(); ``` This is error: ``` <m:innererror> <m:message>The 'ObjectContent`1' type failed to serialize the response body for content type 'application/atom+xml; charset=utf-8'.</m:message> <m:type>System.InvalidOperationException</m:type> <m:stacktrace></m:stacktrace> <m:internalexception> <m:message>'SingleResult`1' cannot be serialized using the ODataMediaTypeFormatter.</m:message> <m:type>System.Runtime.Serialization.SerializationException</m:type> ```

Original source