Skip to content

Allow to configure properties on non-collection complex types by using chaining in the lambda expression#38154

Open
AndriySvyryd wants to merge 1 commit intomainfrom
Issue31236
Open

Allow to configure properties on non-collection complex types by using chaining in the lambda expression#38154
AndriySvyryd wants to merge 1 commit intomainfrom
Issue31236

Conversation

@AndriySvyryd
Copy link
Copy Markdown
Member

Fixes #31236

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR enables configuring nested (non-collection) complex type properties via chained member-access lambdas and dotted-string property paths, adding supporting builder plumbing, error messages, and specification tests (Fixes #31236).

Changes:

  • Added complex-property chain resolution for lambda-based configuration and dotted string names (including auto-creation for lambda intermediates).
  • Introduced new CoreStrings messages for invalid chained/dotted cases (invalid segment, invalid intermediate, collection intermediate, missing intermediate).
  • Expanded model-building tests to validate chained/dotted configuration scenarios and failure modes.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.TestModel.cs Adds new nested complex CLR types used by the new chaining tests.
test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.OwnedTypes.cs Adds tests ensuring owned navigations are rejected as chain intermediates.
test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.NonGeneric.cs Updates non-generic test wrappers to pass dotted names derived from member chains.
test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexType.cs Adds extensive tests for chained lambda and dotted-name configuration of nested complex members.
test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexCollections.cs Adds a dotted-name test for configuring a nested complex collection.
src/EFCore/Properties/CoreStrings.resx Adds new error message resources for complex-property chain resolution failures.
src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs Adds member-chain overloads for Property/PrimitiveCollection/ComplexProperty/Ignore.
src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs Enables chained lambda member access for generic entity type builder APIs.
src/EFCore/Metadata/Builders/EntityTypeBuilder.cs Adds dotted-name support to non-generic builder overloads.
src/EFCore/Metadata/Builders/ComplexPropertyChainHelper.cs New helper to parse/resolve member chains and dotted paths through complex types.
src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs Enables chained lambda member access for complex property builder APIs.
src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs Adds dotted-name support to non-generic complex property builder overloads.
src/EFCore/Metadata/Builders/ComplexCollectionBuilder`.cs Enables chained lambda member access for complex collection builder APIs.
src/EFCore/Metadata/Builders/ComplexCollectionBuilder.cs Adds dotted-name support to non-generic complex collection builder overloads.
src/EFCore/Extensions/Internal/ExpressionExtensions.cs Adds MatchMemberAccessChain() to extract chained member accesses from lambdas.
src/EFCore/EFCore.baseline.json Updates API baseline for newly-added CoreStrings members.
Files not reviewed (1)
  • src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported

Comment thread src/EFCore/Metadata/Builders/ComplexPropertyChainHelper.cs Outdated
Comment thread src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs Outdated
Comment thread test/EFCore.Specification.Tests/ModelBuilding/ModelBuilderTest.ComplexType.cs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported

Comment thread src/EFCore/Properties/CoreStrings.Designer.cs Outdated
Comment thread src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs Outdated
Comment thread src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs
Comment thread src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs
@AndriySvyryd AndriySvyryd force-pushed the Issue31236 branch 2 times, most recently from 1c9a825 to d94e0d4 Compare April 23, 2026 22:33
@AndriySvyryd AndriySvyryd marked this pull request as ready for review April 23, 2026 23:14
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner April 23, 2026 23:14
Copilot AI review requested due to automatic review settings April 23, 2026 23:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 20 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • src/EFCore/Properties/CoreStrings.Designer.cs: Language not supported

Comment thread src/EFCore/Extensions/Internal/ExpressionExtensions.cs
Comment thread src/EFCore/Properties/CoreStrings.resx
Comment on lines +127 to +128
var (innerBuilder, leafName) = Builder.ResolveComplexChainByName(propertyName);
return new PropertyBuilder(innerBuilder.Property(leafName, ConfigurationSource.Explicit)!.Metadata);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: if we want to keep nicer/shorter expression-based code, we can have a method on Builder which accepts the name and a lambda, and internally resolved the inner builder and invokes the lambda on it. Callers would then pass (static) lambdas doing the actual call (Property, PrimitiveCollection).

var metadata = builder.Metadata;

var conflictingMember = metadata.FindMembersInHierarchy(memberName).FirstOrDefault();
if (conflictingMember is ComplexProperty { IsCollection: true })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: can be a 3-legged switch statement (also below).

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.

Allow to configure properties on non-collection complex types by using chaining in the lambda expression

3 participants