Skip to content

Clarify that Include requires navigation property access (#33018) - #39189

Open
SkyDevLab wants to merge 1 commit into
dotnet:mainfrom
SkyDevLab:fix/33018-include-navigation-error-message
Open

SkyDevLab wants to merge 1 commit into
dotnet:mainfrom
SkyDevLab:fix/33018-include-navigation-error-message

Conversation

@SkyDevLab

Copy link
Copy Markdown
Contributor

Fixes #33018

Description

Updated the InvalidIncludeExpression error message from 'property access' to 'navigation property access' to clarify that Include only operates on navigation properties, not regular or complex type properties.

When a user tries to use Include on a complex type property (e.g. context.Set<Customer>().Include(c => c.ShippingAddress)), the previous error message indicated that it does not represent a property access, which was misleading because ShippingAddress is indeed a property—it just isn't a navigation property.

Changes

  • src/EFCore/Properties/CoreStrings.resx: Updated InvalidIncludeExpression string resource.
  • src/EFCore/Properties/CoreStrings.Designer.cs: Updated XML doc comment to match.
  • test/EFCore.Specification.Tests/Query/ComplexTypeQueryTestBase.cs: Added Include_complex_property test verifying the improved exception message when attempting to include a complex property.

Changed InvalidIncludeExpression error message from 'property access' to 'navigation property access' to clarify that Include only works with navigation properties, not regular/complex type properties.

Added Include_complex_property test in ComplexTypeQueryTestBase to verify the improved error message when attempting to Include a complex type property.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Provider-specific overrides are needed to prevent existing test override checks from failing.

1 open finding
What changed in this PR

Clarifies that Include requires navigation-property access and adds regression coverage for complex properties.

Changes:

  • Updates the InvalidIncludeExpression resource message.
  • Synchronizes the generated XML documentation.
  • Adds complex-property Include test coverage.
File Summary
test/​EFCore.Specification.Tests/​Query/​ComplexTypeQueryTestBase.cs Adds invalid Include coverage; provider-specific overrides are needed for existing override checks.
src/​EFCore/​Properties/​CoreStrings.resx Clarifies the navigation-property requirement.
src/​EFCore/​Properties/​CoreStrings.Designer.cs Synchronizes the generated documentation.
Files not reviewed (1)
  • src/EFCore/Properties/CoreStrings.Designer.cs: Generated file

🧠 Review effort: Lite

Comment on lines +113 to +117
[Theory, MemberData(nameof(IsAsyncData))]
public virtual async Task Include_complex_property(bool async)
=> Assert.Equal(
CoreStrings.InvalidIncludeExpression("c.ShippingAddress"),
(await Assert.ThrowsAsync<InvalidOperationException>(() => AssertQuery(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query: improve exception message we throw when trying to use Include on a complex type

2 participants