-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing property error when applying select manually #1231
Comments
Check if it makes any difference if you remove the 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( ) ) ;
} |
Removing the Without wrapping return type of [{"Id":1},{"Id":2},{"Id":3}] When wrapping return type of {"@odata.context":"http://localhost:5247/$metadata#Customers","value":[{"Id":1,"Name":"Customer 1"},{"Id":2,"Name":"Customer 2"},{"Id":3,"Name":"Customer 3"}]} |
@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 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 However.... when I test this, for whatever reason, I noticed that even if I pass something else on the I don't understand what is going on here... it's as if the 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. |
@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 |
Ah, that makes sense. And as @julealgon suggested, I can use the
I can reproduce this behavior too, and to me that does seem like a bug in the library. |
@xuzhg can you take a look at this apparent problem with the partial When I first saw that, I thought maybe the |
Assemblies affected
ASP.NET Core OData 8.0.0 and above
Describe the bug
Because I want to apply
$filter
manually (I can't rely on the default EF integration, but still want to take advantage of my DB), I also have to apply$select
manually. When I do this, selecting a subset of the properties gives an error about a missing property on the EDM instance. When selecting all properties, it works as expected.Reproduce steps
For the code, see this reproduction.
Data Model
See repro code.
EDM (CSDL) Model
See repro code.
Request/Response
http://localhost:5247/Customers?$select=id
Expected behavior
A response with only the ids of all instances.
Additional context
The text was updated successfully, but these errors were encountered: