을 수행, 나는 다음과 같은 코드가 다음 CurrentTestResultController.cs에서중 하나로, OData-V4 엔티티의 컬렉션 동작 후 내 중 하나로, OData-V4 컨트롤러에서 기능
var fn = reportModelBuilder.EntityType<CurrentTestResult>()
.Collection.Function("Breakdown").Returns<int>();
을, 나는 믿을 수 없 간단한 있습니다
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
[HttpGet]
public IHttpActionResult Breakdown()
{
var count = dataService.GetAll()
.Select(x => x.TestResultTypeId)
.Distinct()
.Count();
return Ok(count);
}
기본적으로 컬렉션에있는 모든 CurrentTestResult
엔티티의 경우 집합에서 고유 한 TestResultTypeId
을 반환합니다. (이것은 사소한 작업입니다,하지만 훨씬 더 복잡 정말 삶 시나리오 간체) 쉽게 할 수 있었다
을 -하지만 난 처음 필터에없는 것이 켜져 작동해야 CurrentTestResult
의 수집 . 기본적으로 모든 CurrentTestResult 엔티티에
로컬 호스트/응용 프로그램/odatareport/CurrentTestResult/Default.Breakdown
반환
{
@odata.context: "http://localhost/app/odatareport/$metadata#Edm.Int32",
value: 5
}
(A 올바른 결과를 운영
이 요청, 별개의 5 거기 유형)
그러나이 요청은 필터를 먼저 내림차순으로 시도하면 실패합니다.
이것이 실패 이유를 로컬 호스트/응용 프로그램/odatareport/CurrentTestResult/Default.Breakdown? $ 상단= 2 개
반환 지금까지 내가 하나로, OData 파이프 라인을 이해
{
error: {
code: "",
message: "The query specified in the URI is not valid. The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.",
innererror: {
message: "The requested resource is not a collection. Query options $filter, $orderby, $count, $skip, and $top can be applied only on collections.",
type: "Microsoft.OData.ODataException",
stacktrace:
" at System.Web.OData.EnableQueryAttribute.ValidateSelectExpandOnly(ODataQueryOptions queryOptions) at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext) at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
}
}
}
는 의미가 있습니다. 컨트롤러 메서드는 IQueryable을 반환하고 ODATA $ 필터, $ top 등이 적용됩니다.
나는 이미 필터링 된 집합을 조작하는 기능을 원합니다.
내가 할 수있는 일이 가능한 것입니까?
내가 고장 방법 자체가 그 안에 .GetAll()를 가지고 있지만, MUT 방법 전에 필터링을 적용 할 수있는 방법이있을 수 있음을 얻을 - 그렇지 않으면
,이 모든 아주 무의미 ....
매우 가까이에 있습니다. - 제가 말씀 드렸듯이, 코드를 단계별로 실행하면 옵션이 적용됩니다.하지만 클라이언트에서는 https : // imgur를 얻습니다. com/a/dU32b – Matt
Nevermind, AllQueryOptions 특성을 삭제하는 것을 잊었습니다 - 다시 한 번 감사드립니다! – Matt
훌륭함, 문제 없음 – Moho