实体框架 – WebApi OData:$filter’any’或’all’查询不起作用
|
首先,使用ASP.NET WebApi教程,我创建了一个基本的 ApiController that exposes an Entity Framework model through OData.该服务用于返回json for OData $filter查询. 当我对多值属性执行OData $filter queries that include “any” or “all”查询时会抛出一个ODataException 这是我试图使用的OData查询 / api / Blogs?$filter = any(Tags,Name eq’csharp’) 我的ApiController看起来像这样: public class BlogController : ApiController
{
public BlogsController()
{
this.Entities = new BlogEntities();
}
public ContactEntities Entities { get; set; }
[Queryable(PageSize = 25,AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<Blog> Get()
{
return this.Entities.Blogs;
}
}
博客实体有这个合同 public Blog {
public Guid ID { get; set; }
public string Title { get; set; }
public Tag Tags { get; set; }
}
public Tag {
public Guid ID { get; set; }
public string Name { get; set; }
}
抛出异常 ODataException: Type 'Blog' does not have a property 'Name' 正如你所看到的,我的代码中没有什么是普通的,一切都应该正常工作.可能在Microsoft ASP.NET Web API OData中不支持“任何”和“全部”查询? 解决方法你的任何需要改变一点.尝试这样的东西:~/api/Blogs?$filter=Tags/any(tag: tag/Name eq 'csharp') 这是假设标签实际上返回一个标签的集合,而不仅仅是一个单一的标签,就像你以上. $inlinecount仅支持OData格式的开箱即用.我在这里写道: Web API OData Inlinecount not working 简单的答案是,您可以使其他格式的代码看起来像这样: public PageResult<Customer> Get(ODataQueryOptions<Customer> queryOptions)
{
IQueryable results = queryOptions.ApplyTo(_customers.AsQueryable());
return new PageResult<Customer>(results as IEnumerable<Customer>,Request.GetNextPageLink(),Request.GetInlineCount());
} (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 使用Asp.net MVC 4中的OutputCacheAttribut
- ASP.NET中读取XML文件信息的4种方法与示例代码
- ASP.NET通过分布式Session提升性能
- asp.net-mvc-2 – ASP.NET MVC2 ModelMetadataProviders:重
- asp.net – VS插件:查看标记.存在这样的事情吗?
- asp.net-mvc – ASP.NET MVC V2 – 好友类
- asp.net-mvc – 从Api控制器内生成绝对的url to action
- asp.net-mvc – ASP.Net MVC:如何根据原始的Json数据创建一
- asp.net – IE8 Win7 Facebook Connect问题
- ASP.NET Web应用程序的安装
- 强烈推荐的一个工具ReSharper
- asp.net – 在部分视图中强制使用没有Html.Begin
- asp.net core标签助手的高级用法TagHelper+Form
- ASP.NET:web.config在哪里/如何缓存?
- asp.net-mvc – 如何使用selenium进行ASP.NET MV
- 单元测试 – 如何在ASP MVC 5(Microsoft.AspNet.
- 使用匿名函数减少重复代码
- asp.net-mvc – 隐藏日期时间的ASP.NET MVC格式
- asp.net-mvc – 所有请求获取HTTP错误401.2 – 未
- asp.net-mvc – 如何设置AntiForgeryToken cooki
