-
Notifications
You must be signed in to change notification settings - Fork 473
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
OData with custom modelbuilder attached to Entity framework produces a duplicate left join #2205
Comments
Hi, |
Hi, I created a .net5 branch with the new entity framework updates in prerelease but the same issue occurs. I'll keep this sample project for trying out the suggested updates. |
@smitpatel Does this look like an EF issue with the translation? |
@ajcvickers, @Sreejithpin: Any updates on this? I'm having the same issue with .net core 3.1. According to @PhbsSmn upgrading to .net 5 will not resolve the issue here. @PhbsSmn are you still having this problem? |
This looks like issue with modifications done by user, perhaps OData team can verify. It construct custom object with nested subquery. And using expand in OData query would probably add another subquery for Children, essentially duplicating the join in the LINQ hence generated SQL also has join twice. |
I appreciate the reply @smitpatel . I'm thinking that my issue may be with Automapper. I think my issue is also similar to #863. I was able to get around the issue by following the advice found in that issue using Explicit Expansion. |
That certainly points in the direction of automapper or custom query generated causing additional join. From EF Core side, this is a collection navigation so it is a subquery. Every occurrence of it will cause a join since they are distinct collections. As far my understanding of OData goes, if you ask for expand it will add a collection subquery explicitly causing at least 1 join. So if any query given to OData which already has a subquery for children, and using expand afterwards, 2 joins expected and nothing EF Core or OData can change about it particularly. |
That explanation sounds spot on @smitpatel. Thank you for your time! |
So this means if you introduce automapper it gets solved? |
@PhbsSmn I think AutoMapper was causing my issue in a way. I was already using AutoMapper, and I started using AutoMapper.Extensions.OData to resolve my issue. Now I'm not sure if it was truly AutoMapper's fault or an issue with OData or EF Core. |
I'm having an issue that I first didn't notice because my development machine was fast and my test set small. When publishing to a slower machine with a large dataset, I noticed that when an expand is given with a custom modelbuilder it creates a duplicat join and in turn creating a cross join.
Assemblies affected
Microsoft.AspNetCore.OData 7.4.1
Reproduce steps
I created a small demo project because the issue is easy to reproduce once you know where to look for. Source available on this location https://github.com/PhbsSmn/ExpandIssue.
Expected result
Actual result
The text was updated successfully, but these errors were encountered: