【发布时间】:2015-01-21 05:52:45
【问题描述】:
序列包含多个元素 在 System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 源)在 System.Web.Http.OData.Builder.ODataConventionModelBuilder.RemoveBaseTypeProperties(EntityTypeConfiguration 派生实体,EntityTypeConfiguration baseEntity) 在 System.Web.Http.OData.Builder.ODataConventionModelBuilder.DiscoverInheritanceRelationships()...
这是我的绑定代码:
var modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<PeopleDto>("People");
这是我的控制器代码:
[Queryable]
public IEnumerable<PeopleDto> Get(
[FromUri] Credentials credentials,
ODataQueryOptions<PeopleDto> options,
int departmentId,
DetailLevel detail = DetailLevel.Low)
{
var count = _repository.Filter(x => x.DepartmentId == departmentId && x.Active);
options.ApplyTo(count);
int total = count.Count();
switch (detail)
{
case DetailLevel.Low:
return new Paginable<PeopleDto>(GetMyPeopleLo(departmentId, options), total);
// [...]
}
}
Paginable<T> 实现IEnumerable<T>。 GetMyPeopleLo()(不是真实姓名)方法将选项应用于附加查询。 (我不再需要额外的查询,因为我已经移动了分页代码的位置,但我还没有重构那部分)。
这是 oData 的预发布版本存在问题的情况之一吗?
update:如果我评论 Queryable属性,它似乎有效,但是当我在Querystring中指定的任何过滤器实际上都应用于 count query @ query @ querystring中。 .
【问题讨论】:
-
这听起来像是与您的 DTO 相关的问题。
-
@SLaks DTO 是一个非常苗条的类,其成员都是简单的类型、整数、布尔值和字符串。
-
If I comment out the
Queryableattribute, it seems to work, but any filter that I specify in the querystring is not actually applied when options are applied to thecountquery.
标签: asp.net-web-api odata