实体框架 – 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 – system.web.compilation.debug与system.codedom
- asp.net – 我应该使用哪个PreApplicationStartMethod?
- asp.net中的GridView分页问题
- asp.net-mvc-3 – 我可以传递视图模型到动作链接来生成路由
- asp.net – 可以通过移动设备的Web浏览器上传图片吗?
- asp.net-web-api – ASP.NET WEB API 2 OWIN身份验证unfpor
- asp.net会员提供者Guid userID
- asp.net-mvc – ASP.NET MVC IIS7 FireFox:尾部斜杠在URL中
- asp.net-mvc – 错误:无法在LINQ to Entities查询中构造实
- asp.net-mvc – 如何将MVC 3项目更新为jQuery 1.6?
- 实体框架 – 如何添加外部参考ASP.Net MVC 5身份
- asp.net – Visual Studio不识别新类
- asp.net – 如果缓存破坏程序与内容不匹配,防止捆
- asp.net-mvc – Mvc3 Antiforgery令牌多标签
- asp.net-mvc-3 – Glimpse.axd 403ing在IIS上
- asp.net – 实体框架:坚持在多对多添加新实体,而
- ASP.net MVC AntiForgeryToken over AJAX
- asp.net-core-mvc – 使用MVC Core下载文件
- asp.net – 重音法语字符
- asp.net:控件/页面的页面生命周期顺序与其中的用
