【发布时间】:2013-03-06 17:12:12
【问题描述】:
首先,使用 ASP.NET WebApi 教程,我创建了一个基本的ApiController that exposes an Entity Framework model through OData。该服务用于为 OData $filter 查询返回 json。
当我对多值属性执行 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 中是否可能还不支持“任何”和“所有”查询?
【问题讨论】:
-
另一件值得注意的是,'$inlinecount' odata 选项被忽略了。
标签: entity-framework asp.net-web-api odata