gpt4 book ai didi

odata - SingleResult 无法在 Web API 中按键查询时序列化

转载 作者:行者123 更新时间:2023-12-05 00:26:10 25 4
gpt4 key购买 nike

尝试使用主键 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 Controller 方法不可查询,因此客户端失败。添加注释以修复:[Queryable(AllowedOrderByProperties = "Id")]

关于odata - SingleResult<T> 无法在 Web API 中按键查询时序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22764589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com