Include Expression could not handle extra join #13092
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The code builds and tests pass (verified by our automated build checks)
Commit messages follow this format
Summary of the changes
If you look into following issues, Expressions: Create Navigation Property #12965 and Should we be treating objects created by the user in a query differently from the ones we materialize? #12668, you can see i want to create an extra join on
properties that i marked for it. Everytime i do a query i want to Coalesce these column with a
Joined Table. When i did this i ran into multiple issues, as example when you have a Navigation
Property it was always filled in, EFCore saw this as an object when you use Expression.New and not
anymore as an EntityType. The reason for this is explained in the issues and that's because they
make use of Tracking.
As you can see in the issue Should we be treating objects created by the user in a query differently from the ones we materialize? #12668 i asked if it is a good idea to keep creating an EntityType if
AsNoTracking Expression is added. While i am waiting i created a work around in my code that make
this work on EFCore.Relational level, i made an overwrite of the SelectExpression class. While i was
creating this work around i bumped into a problem and that problem is when i add an
Include
Expression EFCore first creates a SelectExpression and than convert it to an InnerJoin. My
modification adds to the SelectExpression of the Include Expression also a LeftOuterJoin. Because
of this the innerSelectExpression had 2 tables instead of 1. So what i did is use the First table for the
InnerJoin and add my LeftOuterJoin also as a Table to the outerSelectExpression.
This solved my issue, so now i hope this could be implemented in EFCore so i can keep working with
this final work around until there comes a better solution.
Tests for the changes have been added (for bug fixes / features)
Code meets the expectations our engineering guidelines.