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

Stop generating includes in nav expansion for primitive collection properties #34047

Merged
merged 1 commit into from
Jun 21, 2024

Conversation

roji
Copy link
Member

@roji roji commented Jun 21, 2024

The original implementation of primitive collections in 8.0 contained a bug, where nav expansion would generate IncludeExpressions for owned entity types of X when a primitive collection was accessed on X. So e.g. context.Blogs.Select(b => b.Ints) would get rewritten to context.Blogs.Select(b => [IncludeExpression].Ints). Nav expansion does not do this rewriting for regular property accesses, and so shouldn't do it for primitive collection properties either.

This incorrect IncludeExpression was the root cause of #34008 in Cosmos. In relational, owned entities are handled in a special way during translation (ExpandSharedTypeEntities), and this IncludeExpression did not interfere - but it's still incorrect.

Fixes #34008

/cc @maumar

@roji roji requested review from ajcvickers and a team and removed request for ajcvickers June 21, 2024 06:18
@@ -236,8 +236,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
return QueryCompilationContext.NotTranslatedExpression;
}

if (!(includeExpression.Navigation is INavigation includableNavigation
&& includableNavigation.IsEmbedded()))
if (includeExpression.Navigation is not INavigation includableNavigation || !includableNavigation.IsEmbedded())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup only

@@ -564,6 +564,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

case MaterializeCollectionNavigationExpression:
case IncludeExpression:
case PrimitiveCollectionReference:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix


public override async Task Array_of_byte()
{
// TODO
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces the non-shared primitive collection tests for Cosmos - there are 3 failures. I've made a note and will investigate.

@@ -564,6 +564,7 @@ protected override Expression VisitExtension(Expression extensionExpression)

case MaterializeCollectionNavigationExpression:
case IncludeExpression:
case PrimitiveCollectionReference:
return extensionExpression;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@roji roji merged commit fadc821 into dotnet:main Jun 21, 2024
7 checks passed
@roji roji deleted the PrimitiveCollectionInclude branch June 21, 2024 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cosmos: projection of primitive collection throws when entity type embeds owned types
2 participants