Ste*_*eve 4 wcf-data-services odata asp.net-web-api asp.net-web-api-odata
尝试使用主键CourseID针对odata web.api查找单个记录,方法如下:
var editedcourse = container.Courses.Where(c => c.CourseID == ID).SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)
这是错误的:
<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>
Run Code Online (Sandbox Code Playgroud)
默认情况下,web.api控制器方法不可查询,因此客户端失败。添加了注释以修复: [Queryable(AllowedOrderByProperties = "Id")]
| 归档时间: |
|
| 查看次数: |
3462 次 |
| 最近记录: |