首先,使用ASP.NET WebApi教程,我创建了一个基本的 通过OData公开实体框架模型的ApiController。该服务用于返回json以进行OData $过滤查询。
当我执行OData时 $ filter查询包含“any”或“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?