Comments (6)
Check if it makes any difference if you remove the Ok
from your action implementation:
Switch from this:
public ActionResult< IQueryable > Get(
ODataQueryOptions< Customer > queryOptions )
{
IQueryable< Customer > values = s_Customers.AsQueryable( );
return Ok(
queryOptions.SelectExpand.ApplyTo(
values,
new ODataQuerySettings( ) ) );
}
To this:
public ActionResult< IQueryable > Get(
ODataQueryOptions< Customer > queryOptions )
{
IQueryable< Customer > values = s_Customers.AsQueryable( );
return queryOptions.SelectExpand.ApplyTo(
values,
new ODataQuerySettings( ) ) ;
}
from aspnetcoreodata.
Removing the Ok
doesn't compile, if I change the return type to IQueryable
it does, but the return value is missing the @odata.context
property.
Without wrapping return type of Get
in ActionResult
:
[{"Id":1},{"Id":2},{"Id":3}]
When wrapping return type of Get
with ActionResult
and selecting name too:
{"@odata.context":"http://localhost:5247/$metadata#Customers","value":[{"Id":1,"Name":"Customer 1"},{"Id":2,"Name":"Customer 2"},{"Id":3,"Name":"Customer 3"}]}
from aspnetcoreodata.
@KnapSac I tried some different things with your sample and I believe this is the correct way to approach your problem if you only want to apply the select portion from ODataQueryOptions
:
public ActionResult<IQueryable> Get(
ODataQueryOptions<Customer> queryOptions)
{
IQueryable values = s_Customers.AsQueryable();
values = queryOptions.ApplyTo(values, ignoreQueryOptions: ~AllowedQueryOptions.Select);
return Ok(values);
}
Instead of attempting to explicitly apply only the SelectExpand
property, you apply the whole ODataQueryOptions
object and specify which operations you want to exclude. In this case, we "exclude everything but $select
" by passing the negated select option.
However.... when I test this, for whatever reason, I noticed that even if I pass something else on the ignoreQueryOptions
, the actual select operation still happens. The only difference I see is that when $select
is "blocked", it doesn't show in the @odata.context
path.
I don't understand what is going on here... it's as if the [EnableQuery]
attribute is somehow active on the action, even though it is not specified. But then... if I remove the ApplyTo
call completely and just return the original datasource, it does NOT perform the selection at all.
Goes without saying I'm also fairly confused at what is going on here. We might have to wait for someone on the team to clarify that behavior.
In the meantime, I hope this helps.
from aspnetcoreodata.
@KnapSac Thanks @julealgon. Changing the codes as below does work as expected:
public ActionResult< IQueryable > Get(
ODataQueryOptions< Customer > queryOptions )
{
IQueryable< Customer > values = s_Customers.AsQueryable( );
return Ok(
queryOptions.ApplyTo(
values,
new ODataQuerySettings( ) ) );
//return Ok(
// queryOptions.SelectExpand.ApplyTo(
// values,
// new ODataQuerySettings()));
}
The reason is that OData serializer needs the SelectExpandClause to decide which properties should be included. In your previous implementation, OData serializer can't get the 'SelectExpandClause' since you call it from queryOptions.SelectExpand.ApplyTo(...)
.
from aspnetcoreodata.
The reason is that OData serializer needs the SelectExpandClause to decide which properties should be included. In your previous implementation, OData serializer can't get the 'SelectExpandClause' since you call it from
queryOptions.SelectExpand.ApplyTo(...)
.
Ah, that makes sense. And as @julealgon suggested, I can use the ignoreQueryOptions
to skip applying e.g. $filter
, which I can then apply manually.
Instead of attempting to explicitly apply only the
SelectExpand
property, you apply the wholeODataQueryOptions
object and specify which operations you want to exclude. In this case, we "exclude everything but$select
" by passing the negated select option.However.... when I test this, for whatever reason, I noticed that even if I pass something else on the
ignoreQueryOptions
, the actual select operation still happens. The only difference I see is that when$select
is "blocked", it doesn't show in the@odata.context
path.
I can reproduce this behavior too, and to me that does seem like a bug in the library.
from aspnetcoreodata.
@xuzhg can you take a look at this apparent problem with the partial ApplyTo
call? It is incredibly weird to me what is going on, because when I inspect the results after the call, it does seem to respect the ignoreQueryOptions
parameter, but when it comes to showing the results, the serializer somehow still applies the selection to it.
When I first saw that, I thought maybe the [EnableQuery]
filter was being applied somehow, but I checked the codebase yesterday to be sure and I don't see any existing mechanism that would "automatically" include that filter, so it can't be that.
from aspnetcoreodata.
Related Issues (20)
- OData DeepInsert not binding correctly HOT 3
- Strange time zone propagation in the filter HOT 2
- Select query throw an error on a dynamic property dictionary HOT 7
- OData + EfCore Filter dynamic properties HOT 2
- FEATURE REQUEST: be able to conditionally omit properties from response payloads HOT 2
- getting 405 when trying to $batch HOT 18
- `$batch` endpoint doesn't show up in the `$odata` route debugging page
- `ODataBatchMiddleware` should throw when no `ODataBatchHandler` is present
- `ODataBatchMiddleware` documentation doesn't mention `ODataBatchHandler` requirement
- Sorting on a grouped nested dynamic property fails
- $expand fails with DTO - EF cannot translate the query expression HOT 12
- $compute inside $expand not translating $this for single navigations HOT 1
- Issue with Object Expansion After Upgrading AspNetCoreOData HOT 4
- The given model does not contain the type 'System.Object' when using $select with untyped properties HOT 3
- Could not find a property named 'keyName' on type 'MyClass' HOT 2
- Url rewrite behind proxy: `ODataOutputFormatter.BaseAddressFactory` does not affect `@odata.nextLink` urls HOT 4
- ODataResourceSerializer and ODataResource.SkipPropertyVerification HOT 1
- OData version error when requesting 4.01 bulk update
- $select non-nullable property inside a nullable complex object throws
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspnetcoreodata.