odata – 按键查询时,在Web API中不能序列化SingleResult

odata – 按键查询时,在Web API中不能序列化SingleResult,第1张

概述尝试使用主要密钥CourseID查找单个记录对odata web.api使用: var editedcourse = container.Courses.Where(c => c.CourseID == ID).SingleOrDefault(); 这是错误: <m:innererror> <m:message>The 'ObjectContent`1' type failed to se 尝试使用主要密钥CourseID查找单个记录对odata web.API使用:

var editedcourse = container.Courses.Where(c => c.CourseID == ID).SingleOrDefault();

这是错误:

<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>
解决方法 默认情况下,web.API控制器方法不可查询,因此客户端失败.添加了要修复的注释:[queryable(AllowedOrderByPropertIEs =“ID”)] 总结

以上是内存溢出为你收集整理的odata – 按键查询时,在Web API中不能序列化SingleResult全部内容,希望文章能够帮你解决odata – 按键查询时,在Web API中不能序列化SingleResult所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1065134.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存