You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was playing around with a sample API on my side and noticed that when I used either .Created or .Updated methods from ODataController as the return values for POST/PUT/PATCH operations, $select projections did not work at all.
Example:
[EnableQuery][HttpPut("{key}")]publicActionResult<WeatherForecast>Put([FromODataUri]Guidkey,[FromBody]WeatherForecastupdate){
...
var update = MyRepository.Update(key, update)
...
return Updated(update);}
PUT /api/forecasts(a84f1de3-5c2b-42d3-bc52-b6519e51e6af)?$Select=Summary with Prefer: return=representation
The projection is completely ignored and I get a 200 response with the full payload.
If I change the return from Created(entity)/Updated(entity) to just Ok(entity):
[EnableQuery][HttpPut("{key}")]publicActionResult<WeatherForecast>Put([FromODataUri]Guidkey,[FromBody]WeatherForecastupdate){
...
var update = MyRepository.Update(key, update)
...
return update;}
Then the projection suddenly works for the exact same request. Artificially changing to SingleResult also works just fine. Obviously, none of those are acceptable workarounds since one has to give up on the Location header and payload control functionalities.
Attempting to use both .Created/.Updated with SingleResult results in an exception (probably expected, but I figured I'd give it a try):
System.Runtime.Serialization.SerializationException: 'SingleResult1' cannot be serialized using the OData output formatter. at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.GetSerializer(Type type, Object value, HttpRequest request, IODataSerializerProvider serializerProvider) at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.WriteToStreamAsync(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, HttpRequest request, IHeaderDictionary requestHeaders, IODataSerializerProvider serializerProvider) at Microsoft.AspNetCore.OData.Results.UpdatedODataResult1.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.OData.Routing.ODataRouteDebugMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
.Created and .Updated should work as per the spec with EnableQuery so that one can manipulate the return payload using the query.
The text was updated successfully, but these errors were encountered:
Got the same issue as I would like to avoid making a second call to get the specific content of a created or updated entity.
I believe that the error stack trace given by @julealgon indicates the actual underlying issue, i.e. serializing.
In addition to that, when making use if Created/CreatedODataResult or Updated/UpdatedODataResult execution will fail earlier as the internal methods GenerateLocationHeader and GenerateEntityId cannot handle an IQueryable object.
I was playing around with a sample API on my side and noticed that when I used either
.Created
or.Updated
methods fromODataController
as the return values forPOST/PUT/PATCH
operations,$select
projections did not work at all.Example:
PUT /api/forecasts(a84f1de3-5c2b-42d3-bc52-b6519e51e6af)?$Select=Summary
withPrefer: return=representation
The projection is completely ignored and I get a 200 response with the full payload.
If I change the return from
Created(entity)/Updated(entity)
to justOk(entity)
:Then the projection suddenly works for the exact same request. Artificially changing to
SingleResult
also works just fine. Obviously, none of those are acceptable workarounds since one has to give up on theLocation
header and payload control functionalities.Attempting to use both
.Created/.Updated
withSingleResult
results in an exception (probably expected, but I figured I'd give it a try):.Created
and.Updated
should work as per the spec withEnableQuery
so that one can manipulate the return payload using the query.The text was updated successfully, but these errors were encountered: