AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

8.0.3 Broke Expand

Open pksorensen opened this issue 3 years ago • 7 comments

I am using this library in a custom project but not with the odatacontrollers, but a custom endpoint implementation instead.

                var context = new ODataQueryContext(manager.Model, type, new Microsoft.OData.UriParser.ODataPath());
                IODataFeature odataFeature = request.HttpContext.ODataFeature();
                odataFeature.RoutePrefix =  "/api/";
              
                context.DefaultQuerySettings.EnableFilter = true;
                context.DefaultQuerySettings.EnableExpand = true;
                context.DefaultQuerySettings.EnableSelect = true;
                context.DefaultQuerySettings.EnableCount = true;
                context.DefaultQuerySettings.EnableSkipToken = true;

                var odata = new ODataQueryOptions(context, request);
              
                metadataQuerySet = odata.ApplyTo(metadataQuerySet);

Basically doing the above stuff to apply odata filtering on my IQueryable data source dynamically.

This broke with $expand on 8.0.3 from 8.0.2

In 8.0.2, https://github.com/OData/AspNetCoreOData/blob/8.0.2/src/Microsoft.AspNetCore.OData/Query/Query/SelectExpandQueryOption.cs#L366 is used to

 var autoSelectProperties = EdmHelpers.GetAutoSelectProperties(null,
                baseEntityType, model, modelBoundQuerySettings);

image

which allowed the pathStructuredType to be null. I have not figured out if this should be anything other than null or if its null due to my way of using the library.

But in 8.0.3, this was refactored to use https://github.com/OData/AspNetCoreOData/blob/8.0.3/src/Microsoft.AspNetCore.OData/Query/Query/SelectExpandQueryOption.cs#L382 and https://github.com/OData/AspNetCoreOData/blob/8.0.3/src/Microsoft.AspNetCore.OData/Edm/AutoSelectExpandHelper.cs#L148 which throws an exception when this is null

image

I been debugging the two versions, and cant find anything why this breaks my stuff other than the null argument. Could there be an underlaying issue or is it possible to get help doing a new example where we do odata filering out of the core odatacontroller stuff?

pksorensen avatar Oct 11 '21 14:10 pksorensen

Same as https://github.com/OData/WebApi/issues/2584

a possible fix: https://github.com/OData/WebApi/pull/2585

xuzhg avatar Oct 11 '21 16:10 xuzhg

I fixed it client side by adding my entitites as entitysets also to the model.

image

Not yet discovered if this has sideeffects

pksorensen avatar Oct 11 '21 16:10 pksorensen

I added a check before going to the extension method. Running the nightly build, are you interested in trying the nightly bit when it's ready?

xuzhg avatar Oct 11 '21 16:10 xuzhg

i have a few things that i need to publish tomorrow, but after that i can test.

I did not really find any documentation / understanding of what the AddEntitySet actually is. What is an entityset in odata terms? I just reverse engineered the code to find that i could add an "entityset" and it would not get the null reference.

Would you advise me to not use the entityset if your fix solves the problem?

pksorensen avatar Oct 11 '21 17:10 pksorensen

Entity sets are top-level collection-valued resources. More details:

http://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.html#sec_EntitySet

I think the latest fix "Microsoft.AspNetCore.OData.8.0.3-Nightly202110111705.nupkg" can fix your problem without adding entity set. However, need you double confirm.

For the nightly, you can find the feed at: https://github.com/OData/AspNetCoreOData/tree/8.0.3#34-nightly-builds

xuzhg avatar Oct 11 '21 17:10 xuzhg

I was having this issue in 8.0.3 and I have upgraded to 8.0.4 and no longer get the exception. However, no results seemed to be returned as part of the expand.

It might just be how I set things up, so I have created this example https://github.com/roly445/odata-test and test it with https://localhost:44320/v1/Users(e1bead22-a1fb-400c-8911-061490c688fb)/Devices?$expand=DeviceFeatures

roly445 avatar Nov 10 '21 01:11 roly445

@pksorensen Was your issue resolved? If yes, we can close this issue

KenitoInc avatar Apr 14 '22 08:04 KenitoInc