OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
857 stars 473 forks source link

IQueryable, IQueryable<T>, or Something Else? #1195

Open TonyValenti opened 6 years ago

TonyValenti commented 6 years ago

Hi All, I'm working to expose a data set of strongly typed objects that represent JSON deserializations to Microsoft Excel using OData and ASPNET Core (In Excel, Data Ribbon > New Query > From Other Sources > From OData Feed) . I feel like I'm running in circles. I have a method that returns a List that I want to expose. Specifically, it looks like this:

           //This is the data I want to expose.  All properties of every member of this result.
            var results = API.List().AsQueryable();

When I decorate my call like this:

        public virtual IQueryable<TJson> Get(ODataQueryOptions<TJson> options) {
            var results = API.List().AsQueryable();

            var ret = options.ApplyTo(results) as IQueryable<TJson>;

            return ret;
        }

Lots of the data seems to appear, but I get errors like this showing in the log:

System.Runtime.Serialization.SerializationException: Cannot serialize a null 'ResourceSet'.

and when I try to expand a record, all I get from Excel is 'Error'. Also, it seems as though some queries actually modify the return type of TJSON into some object that only has select properties of TJson, which obviously doesn't work because when I as IQueryable<TJson> it becomes null.

When I decorate my call like this:

public virtual IQueryable Get(ODataQueryOptions<TJson> options) {
            var results = API.List().AsQueryable();

            var ret = options.ApplyTo(results);

            return ret;
        }

I see these messages in the log:

No output formatter was found for content type '' to write the response.
Microsoft.AspNetCore.Mvc.Internal.ObjectResultExecutor: Warning: No output formatter was found for content type '' to write the response.

And Excel shows a message like the following message:

DataSource.Error: OData: Request failed: The remote server returned an error: (406) Not Acceptable. (Not Acceptable)
Details:
    DataSourceKind=OData
    DataSourcePath=http://127.0.0.1:8881/1/Remoting/Services/ODATA/MatterApi
    Url=http://127.0.0.1:8881/1/Remoting/Services/ODATA/MatterApi

I'm not sure if I'm running into a bug or something else. Can anyone point me in the right direction?

robward-ms commented 6 years ago

@TonyValenti - In the case of returning IQueryable, for formatter is getting confused because it's not sure what to do with that result. IQueryable should be correct.

There seesm to be an issue converting API.List() to IQueryable. What is the return type of API.List()? Have you inspected the results using a breakpoint in your controller?

AlanWong-MS commented 6 years ago

@TonyValenti we're currently reviewing open issues in preparation for our upcoming WebAPI 7.x release. Is the behavior that you're seeing still applicable? Please review Rob's post above. Thank you.