Skip to content
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

The given model does not contain the type 'System.Object' when using $select with untyped properties #1250

Open
jusbuc2k opened this issue May 30, 2024 · 3 comments
Assignees
Labels

Comments

@jusbuc2k
Copy link

jusbuc2k commented May 30, 2024

Assemblies affected
Microsoft.AspNetCore.OData 8.25 and previous versions

Describe the bug
An exception is thrown when using $select on an untyped property after following this guide to setup untyped properties:

https://devblogs.microsoft.com/odata/enable-un-typed-within-asp-net-core-odata/#:~:text=In%20ASP.NET%20Core%20OData%2C%20it%E2%80%99s%20easy%20to%20build,a%20single%20value%20untyped%20property%2C%20for%20example%20Data.

Reproduce steps

  1. Clone the sample repo referenced here https://github.com/xuzhg/MyAspNetCore/tree/master/src/UntypedApp
  2. Open the UntypedApp.sln solution project
  3. Add [EnableQuery] to line 18 on the HandlePeopleController
  4. Run the project
  5. Perform a GET request using to the path /odata/people?$select=Id,Name,Data

Data Model
See the example repo at https://github.com/xuzhg/MyAspNetCore/tree/master/src/UntypedApp

EDM (CSDL) Model
See the example repo at https://github.com/xuzhg/MyAspNetCore/tree/master/src/UntypedApp

Request/Response

GET http://localhost:5299/odata/people?$select=Id,Name,Data

{
  "error": {
    "code": "",
    "message": "The query specified in the URI is not valid. The given model does not contain the type 'System.Object'.",
    "details": [],
    "innererror": {
      "message": "The given model does not contain the type 'System.Object'.",
      "type": "Microsoft.OData.ODataException",
      "stacktrace": "   at Microsoft.AspNetCore.OData.Query.Expressions.QueryBinderContext..ctor(QueryBinderContext context, ODataQuerySettings querySettings, Type clrType)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.SelectExpandBinder.ProjectAsWrapper(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource, OrderByClause orderByClause, ComputeClause computeClause, Nullable`1 topOption, Nullable`1 skipOption, Nullable`1 modelBoundPageSize)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.SelectExpandBinder.BuildSelectedProperty(QueryBinderContext context, Expression source, IEdmStructuredType structuredType, IEdmStructuralProperty structuralProperty, PathSelectItem pathSelectItem, IList`1 includedProperties)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.SelectExpandBinder.BuildPropertyContainer(QueryBinderContext context, Expression source, IEdmStructuredType structuredType, IDictionary`2 propertiesToExpand, IDictionary`2 propertiesToInclude, IList`1 computedProperties, ISet`1 autoSelectedProperties, Boolean isSelectingOpenTypeSegments, Boolean isSelectedAll)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.SelectExpandBinder.ProjectElement(QueryBinderContext context, Expression source, SelectExpandClause selectExpandClause, IEdmStructuredType structuredType, IEdmNavigationSource navigationSource)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.SelectExpandBinder.BindSelectExpand(SelectExpandClause selectExpandClause, QueryBinderContext context)\r\n   at Microsoft.AspNetCore.OData.Query.Expressions.BinderExtensions.ApplyBind(ISelectExpandBinder binder, IQueryable source, SelectExpandClause selectExpandClause, QueryBinderContext context)\r\n   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplySelectExpand[T](T entity, ODataQuerySettings querySettings)\r\n   at Microsoft.AspNetCore.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)\r\n   at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuted(ActionExecutedContext actionExecutedContext, Object responseValue, IQueryable singleResultCollection, ControllerActionDescriptor actionDescriptor, HttpRequest request)"
    }
  }
}

Expected behavior
I expect to get the Id, Name, and Data properties with their values just as if I had omitted the $select parmeter.

Screenshots

Working
image

Not Working
image

Additional context

@jusbuc2k jusbuc2k added the bug Something isn't working label May 30, 2024
@julealgon
Copy link
Contributor

I can also repro. The issue only happens when the Data property is included in the list of select properties, and it happens regardless of the specific concrete value in it (crashes when trying to select it for a single person as well with many different records).

Looks like this was an oversight from the original article @xuzhg . Is this a bug, or is there something missing in the sample to allow for the property to be selected?

@xuzhg
Copy link
Member

xuzhg commented Jun 3, 2024

@jusbuc2k @julealgon Thanks for reporting this.

Query option on untyped value is not supported yet. When I design/implement, I do have the following:

We should support to enable query option on untyped property, same as dynamic property
~/odata/people/1/data?$filter=city eq ‘abc’

Since it’s a more complex scenario, let’s scope this out.

Untyped for operation parameter and return type is scoped out also.

@xuzhg xuzhg self-assigned this Jun 3, 2024
@xuzhg xuzhg added feature and removed bug Something isn't working labels Jun 3, 2024
@jusbuc2k
Copy link
Author

jusbuc2k commented Jun 4, 2024

If we could even make it pluggable in some way, like an interface we can put in DI to implement the important bits, like a Filter/Select/Order binder, so we could implement it in some way that would be specific to a project that might be enough for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants