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

Expand on second level causing error if more than one properties are included in expand on the first level #2017

Closed
mmichtch opened this issue Jan 12, 2020 · 10 comments
Assignees
Milestone

Comments

@mmichtch
Copy link

mmichtch commented Jan 12, 2020

Expand of the property(properties) on the sub-object is failing if more than one object is included in the expand directive on the first level.

Assemblies affected

Microsoft.AspNetCore.OData 7.3.0
Microsoft.EntityFrameworkCore.SqlServer 3.1.0

Reproduce steps

Send HTTP get request to the following URL:
https://localhost:5001/odata/Books?$expand=Authors,CookBook($expand=Recipes)

Expected result

Service should render object with two sub-objects and expand collection property in the respected sub-object.

Actual result

Application failing with exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')

Additional detail

following requests are working as expected:
https://localhost:5001/odata/Books?$expand=Authors,CookBook
https://localhost:5001/odata/Books?$expand=CookBook($expand=Recipes)

you can find source code for the sample project in:
https://github.com/mmichtch/ODataSample

@mmichtch mmichtch changed the title Expand on second level causing error if more than one expand present on the first level Expand on second level causing error if more than one properties are included in expand on the first level Jan 12, 2020
@mmichtch
Copy link
Author

Lazy load solves this problem as well as #2016. There is mentioning the discussion about disadvantages of the Lazy load,so far I could not fine any ill effects. SQL seems to be of the same quality and performance does not show any symptoms of degradation.
still, it looks like a bug, without lazy load

@mmichtch
Copy link
Author

mmichtch commented Jan 14, 2020

Correction, Lazy Load did not solve issue completely.
I have added another collection property on the second level object and now following requests are not working:
https://localhost:5001/odata/Books?$expand=Authors,CookBook($expand=Recipes)
https://localhost:5001/odata/Books?$expand=CookBook($expand=Recipes,BlogEntries)

At the same time following requests are working as expected:
https://localhost:5001/odata/Books?$expand=CookBook,Genres
https://localhost:5001/odata/Books?$expand=CookBook($expand=Recipes)
https://localhost:5001/odata/Books?$expand=CookBook($expand=BlogEntries)

Bottom line, with or without Lazy Load, there is a bug related in implementation of the "$expand" directive.

@xuzhg xuzhg self-assigned this Jan 14, 2020
@xuzhg
Copy link
Member

xuzhg commented Jan 14, 2020

It seems it's same as #2016.

@mmichtch
Copy link
Author

Yes, it does look very similar to #2016, but this one concentrates on expands on the sub-objects. It is difficult to see from outside what specific parts of the framework are failing, and if internally it is same mechanism. But if those two issues will be merged, please make sure that scenario described here is also tested.

@asyncoder
Copy link

FYI

dotnet/efcore#19616 (comment)

@asyncoder
Copy link

@xuzhg do you have any updates regarding this? This is a blocker for many people including me willing to upgrade to .NET Core 3.x

@mikepizzo mikepizzo added this to the 7.4 milestone Mar 11, 2020
@keatkeat87
Copy link

same problem here, any workaround ?

@mmichtch
Copy link
Author

FYI, just updated Microsoft.AspNetCore.OData to 7.4.0 - still the same error.
are there any updates on this issue?

@mmichtch
Copy link
Author

mmichtch commented May 1, 2020

Just updated test application to with preview versions of the components:

  • Microsoft.AspNetCore.OData Version="7.4.0"
  • Microsoft.EntityFrameworkCore.InMemory Version="5.0.0-preview.3.20181.2"
  • Microsoft.EntityFrameworkCore.SqlServer Version="5.0.0-preview.3.20181.2"
  • Microsoft.EntityFrameworkCore.Tools Version="5.0.0-preview.3.20181.2

error resolved

@xuzhg
Copy link
Member

xuzhg commented Sep 14, 2020

Close it since it got fixed after update the EF Core library.

@xuzhg xuzhg closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants