实体框架 – 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-web-api – WebAPI:403在发布网站后被禁止
- asp.net-mvc – ASP.NET MVC 3 Beta 1 Block访问Razor视图
- 如何从经典ASP输出Excel * .xls文件
- asp.net-mvc-4 – 在EF迁移配置类的Seed方法中获取App_Data
- asp.net-mvc-4 – MVC 4 Razor如果拆分div标签
- asp.net-mvc-3 – Telerik MVC网格,在运行时从集合或字典中
- asp.net-web-api – 在WebApi OData中为OData服务文档基URL
- ASP.NET两个截取字符串的方法分享
- ASP.NET异步方法问题
- asp.net-mvc – Url.Action生成查询字符串,以任何方式生成完
