加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – 无法识别Web Api [可查询]属性

发布时间:2020-12-16 04:02:19 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试在Web Api类中启用OData,并将属性[Queryable]添加到我的查询中 using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Http;using System.Web.Http;public class ItemsController : ApiController{
我正在尝试在Web Api类中启用OData,并将属性[Queryable]添加到我的查询中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

public class ItemsController : ApiController
{
    ...
    [HttpGet]
    [Queryable]
    public IQueryable<Item> GetItems()
    {
        return _repository.Items.AsQueryable();
    }

但Visual Studio告诉我

‘Queryable’ is not an attribute”

我收到编译错误:

CS0616: ‘System.Linq.Queryable’ is not an attribute class

如果我符合该属性

[System.Web.Http.Queryable]

我收到另一条错误消息

CS0234: The type or namespace name ‘Queryable’ does not exist in the
namespace ‘System.Web.Http’ (are you missing an assembly reference?)

任何想法为什么[可查询]似乎没有被识别?这是一个Web表单应用程序,以后会添加Web API.

解决方法

我的坏,它现在是一个单独的Nuget包

Install-Package Microsoft.AspNet.WebApi.OData -Version 5.3.1

我希望微软能够更新他们的教程和docs当他们做这种事情时.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读