-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ArgumentException thrown When GroupJoin is applied on a DbSet as a first join and NOT when applied as a second or later #27343
Comments
One Update: Found an answer of the same issue on StackOverflow which works: replace GroupJoin with SelectMany
But this will require all of LINQs in my project to go through these syntactical changes which is really very risky and not recommened. Essentially the question arises as to how the same kind of query works on LinqPad7? |
One more peculiar case: Instead of using generic object "entitySet" if I then use direct DbContext.DbSet reference, then all the errors go away and the Sql gets generated correctly:
But this isn't the correct design for our architecture and I would like to know if I am missing something very obvious here? |
Issue is the interface here. When you are passing |
Two queries then:
|
GroupJoin doesn't have any equivalent operation on database. When user writes GroupJoin followed by SelectMany it is converted to a JOIN operation in database depending on the structure. See https://docs.microsoft.com/ef/core/querying/complex-query-operators#left-join When EF core is trying to convert GroupJoin-SelectMany to LeftJoin operation, in first one it runs into issue because the generic type on the GroupJoin/SelectMany operation is different from the keyselector passed. When you write GroupJoin in later phase (as in query 2), for whatever reason that type mismatch is not happening. Compiler needs to assign a lot of different generic type when creating expression tree, this just happens to align with what EF Core can process. The 2nd query in last post works because it doesn't utilize the code path of |
Thanks @smitpatel for the detailed explanation, will get back to you if there’s more clarification required. |
Hi @smitpatel - Any expected release version where in this issue will be fixed? As our product has been shipped as SaaS, even the clients can write LINQ queries and they have written plenty of such "GroupJoins", hence it sounds very odd to ask everyone to have this change made manually over their solutions and not to mention it is prone to many human-errors. Hence we would like to know as to when can we expect this "type-bug" to be resolved and shipped with which version, also can we prioritize this so that we can complete the migration successfully and in a timely manner? CC: @ajcvickers |
@ankitmatrix08 We triage new issues on Tuesdays and Fridays. For general information on what is and is not patched, see release planning. |
@ajcvickers Thanks! I will wait for tomorrow for you to come back on this with the priority and release plan. As mentioned above, this is a very tricky situation for us as we can't effort to have too many code changes for this migration, and this issue seems to be a very basic one that should work anyhow. |
Any update on this? |
@ankitmatrix08 Some team members were out on Friday, so we were not able to fully assess this. However, based on the existence of workarounds and that we so far only have one customer report, I think given the policy for patching, it's unlikely that we will patch for this issue. |
@ankitmatrix08 Can you share your model? |
@AndriySvyryd Please find the below sample project showcasing the failure scenario with the required models:
Exception Report and Expression Tree:
|
Marking as good-first-issue. efcore/src/EFCore/Query/Internal/QueryableMethodNormalizingExpressionVisitor.cs Lines 492 to 516 in 22a533c
The root cause is that we utilize sequence type of outer & inner when creating generic method. The outer/inner could be of concrete type even though the GroupJoin is defined over interface types. We should use generic types from the GroupJoin operation (or keyselectors) |
1. Exception Case:
LINQ: Here, I have a query which is doing a GroupJoin on an DbSet and then adding other inner joins.
Repository.ConvertToBigIntTable -> This is an output of a call to a Table-Valued function which returns an IQueryable (T is a Keyless entity having a long Id field)
Exception:
Stack Trace:
NOTE: Interestingly trying to do a very similar operation on LinqPad7 seems to work:
2. Working Case
LINQ: Here, I have a query which is performing inner joins on few DbSets and then applying GroupJoin on one of the DbSet.
Repository.ConvertToBigIntTable -> This is an output of a call to a Table-Valued function which returns an IQueryable (T is a Keyless entity having a long Id field)
Generated Expression:
Generated SQL:
EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Win 10 Pro
IDE: Visual Studio 2022 v17.0.4
The text was updated successfully, but these errors were encountered: