【问题标题】:OData SingleResult is Ambiguous in System.Web.HttpSystem.Web.Http 中的 OData SingleResult 不明确
【发布时间】:2014-09-22 09:13:41
【问题描述】:

我不熟悉将 OData 与 Web Api 结合使用。我从数据库优先 EF 6 方法定义了我的模型,并添加了 OData 控制器。生成的代码在以下方面出错:

< EnableQuery > _

    Public Function [Get](<FromODataUri> key As Integer) As SingleResult(Of Product)
        Dim result As IQueryable(Of Product) = db.Product.Where(Function(p) p.ID= key)
        Return SingleResult.Create(result)
    End Function

错误出现在 SingleResult 上,提供以下错误:SingleResult is ambiguous in system.web.http.

关于导致此错误的原因有什么建议吗?非常感谢!

【问题讨论】:

    标签: asp.net-web-api odata entity-framework-6.1


    【解决方案1】:

    确保您没有安装多个 OData NuGet。我安装了 2.1 和 2.2(用于 OData v4 支持),这给了我完全相同的问题。

    【讨论】:

      【解决方案2】:

      试试这个:

      Return SingleResult(of Product).Create(result)
      

      【讨论】:

      • 谢谢,但是VS实际上也强调了带有错误的函数调用:
      • 公共函数 [Get]( key As Integer) As SingleResult(Of Product)。据说它在 System.Web.Http 中是模棱两可的。我觉得这里有两件事在竞争,不确定如何正确识别 SingleResult(如果这有意义的话)。就像我在参考资料或 web.config 中遗漏了什么?
      • 现在,我更改了函数: Public Function [Get]( key As Integer) As IHttpActionResult Return Ok(db.Product.SingleOrDefault(Function(t) t.ID= key) ) 结束函数
      猜你喜欢
      • 1970-01-01
      • 2014-01-23
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 2014-11-13
      • 1970-01-01
      • 2018-06-03
      • 2019-08-29
      相关资源
      最近更新 更多