-
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
Fix to #1833 - Support filtered Include #20279
Conversation
bf58c4a
to
59e2c7e
Compare
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.Expressions.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
59e2c7e
to
8beca75
Compare
new version up @smitpatel |
and all checks failed 😄 |
@@ -1290,6 +1290,12 @@ | |||
<data name="IncludeOnNonEntity" xml:space="preserve"> | |||
<value>Include has been used on non entity queryable.</value> | |||
</data> | |||
<data name="MultipleFilteredIncludesOnSameNavigation" xml:space="preserve"> | |||
<value>Multiple filtered include operations on the same navigation '{navigationName}' are not supported.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are supporting more than just where then we need to create a new term rather than filtered include
@dotnet/efcore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the spirit" of the feature is still about filter. Ordering is only added for suppose of Skip/Take, so maybe keeping the name is not so bad. We will never have projections in there, that's for sure so its not like we are future-proofing with the less specific name.
However I'm fine if ppl think otherwise. Something like "modified include", "altered include", "composable include"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional include.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Extended include", "augmented include"
But taking a step back we don't support multiple normal includes on the same navigation either, so perhaps just make the message more generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works for me. lets see what others say
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we support it in a sense that it doesn't throw :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new message:
Different filters: 'navigation
.Where(x => x.Name != "Bar")
.OrderByDescending(x => x.Name)
.Take(3)' and 'navigation
.Where(x => x.Name != "Foo")
.OrderBy(x => x.Id)
.Take(3)' have been applied on the same included navigation. Only one unique filter per navigation is allowed. For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393.
8beca75
to
0b276c5
Compare
fixed again, missed one of the sqlite tests - they all need to be skipped cause lack of apply |
0b276c5
to
e737094
Compare
another version up @smitpatel |
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
e737094
to
44bd275
Compare
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Outdated
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Show resolved
Hide resolved
|
||
[ConditionalTheory] | ||
[MemberData(nameof(IsAsyncData))] | ||
public virtual async Task Filtered_include_with_Distinct_throws(bool async) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test where navigation is registered as reference navigation in EF Core metadata but implements IEnumerable<> and will allow you to write filtered include syntax. (Essentially filterExpression when put on non collection navigation should throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do people actually do that? Seems like very contrived scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's negative case example. Rather than ignoring (which what we are doing currently when we see non-navigation in Include, we should change that), we can throw a better error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On note of reference nav which implements IEnumerable, it is not impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More tests on further nesting
Nested filtered includes e.g. filter on c.Orders & then include filter on o.OrderDetails
d9f78c4
to
48dfd16
Compare
@@ -747,8 +747,8 @@ | |||
<data name="AmbiguousForeignKeyPropertyCandidates" xml:space="preserve"> | |||
<value>Both relationships between '{firstDependentToPrincipalNavigationSpecification}' and '{firstPrincipalToDependentNavigationSpecification}' and between '{secondDependentToPrincipalNavigationSpecification}' and '{secondPrincipalToDependentNavigationSpecification}' could use {foreignKeyProperties} as the foreign key. To resolve this configure the foreign key properties explicitly on at least one of the relationships.</value> | |||
</data> | |||
<data name="InvalidIncludeLambdaExpression" xml:space="preserve"> | |||
<value>The {methodName} property lambda expression '{includeLambdaExpression}' is invalid. The expression should represent a property access: 't => t.MyProperty'. To target navigations declared on derived types, specify an explicitly typed lambda parameter of the target type, E.g. '(Derived d) => d.MyProperty'. For more information on including related data, see http://go.microsoft.com/fwlink/?LinkID=746393.</value> | |||
<data name="InvalidIncludeExpression" xml:space="preserve"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TMI?
48dfd16
to
6317688
Compare
new version up @smitpatel |
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Outdated
Show resolved
Hide resolved
test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs
Show resolved
Hide resolved
test/EFCore.Sqlite.FunctionalTests/Query/ComplexNavigationsQuerySqliteTest.cs
Show resolved
Hide resolved
src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
b662b2f
to
bb11d83
Compare
Allows for additional operations to be specified inside Include/ThenInclude expression when the navigation is a collection: - Where, - OrderBy(Descending)/ThenBy(Descending), - Skip, - Take. Those additional operations are treated like any other within the query, so translation restrictions apply. Collections included using new filter operations are considered to be loaded. Only one filter is allowed per navigation. In cases where same navigation is included multiple times (e.g. Include(A).ThenInclude(A_B).Include(A).ThenInclude(A_C)) filter should only be applied once. Alternatively the same exact filter should be applied to all.
bb11d83
to
21b9a35
Compare
Are you planning to put this any 3.x version? |
@onurh no, this new feature will not be backported to any 3.x version. However, consider trying out the 5.0 previews - they are generally well-tested and work well. |
Allows for additional operations to be specified inside Include/ThenInclude expression when the navigation is a collection:
Those additional operations are treated like any other within the query, so translation restrictions apply.
Collections included using new filter operations are considered to be loaded.
Only one filter is allowed per navigation. In cases where same navigation is included multiple times (e.g. Include(A).ThenInclude(A_B).Include(A).ThenInclude(A_C)) filter should only be applied once.
Alternatively the same exact filter should be applied to all.