Add support for projectable constructors#155
Draft
PhenX wants to merge 8 commits intocopilot/support-classic-methods-transformationfrom
Draft
Add support for projectable constructors#155PhenX wants to merge 8 commits intocopilot/support-classic-methods-transformationfrom
PhenX wants to merge 8 commits intocopilot/support-classic-methods-transformationfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds support for [Projectable] constructors in Entity Framework Core Projectables. This feature allows developers to mark constructors with the [Projectable] attribute, enabling EF Core to convert constructor calls in LINQ queries into SQL-compatible projections. The implementation transforms constructor bodies into object-initializer expressions (new T() { Prop = ... }) that EF Core can translate to SQL.
Changes:
- Extended
ProjectableAttributeto support constructors (AttributeTargets.Constructor) - Added source generator logic to process projectable constructors and convert their bodies into member-initializer expressions
- Implemented runtime expression replacement for
NewExpressionnodes in LINQ queries - Added diagnostic EFP0007 for missing parameterless constructors
- Added comprehensive test coverage with 22 test scenarios covering various constructor patterns
Reviewed changes
Copilot reviewed 102 out of 102 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/EntityFrameworkCore.Projectables.Abstractions/ProjectableAttribute.cs | Extended attribute to allow constructors as targets |
| src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs | Added constructor lookup support using "_ctor" naming convention |
| src/EntityFrameworkCore.Projectables/Services/ProjectableExpressionReplacer.cs | Added VisitNew method to expand projectable constructors at runtime with recursion protection |
| src/EntityFrameworkCore.Projectables.Generator/ProjectableInterpreter.cs | Main code generation logic for constructors including base/this initializer handling |
| src/EntityFrameworkCore.Projectables.Generator/ConstructorBodyConverter.cs | New file that converts constructor bodies to member-init expressions with support for locals, if/else, and property references |
| src/EntityFrameworkCore.Projectables.Generator/Diagnostics.cs | Added EFP0007 diagnostic for missing parameterless constructors |
| src/EntityFrameworkCore.Projectables.Generator/AnalyzerReleases.Shipped.md | Documentation for new diagnostic |
| tests/EntityFrameworkCore.Projectables.Generator.Tests/ProjectionExpressionGeneratorTests.cs | 22 new test cases covering constructor scenarios |
| tests/EntityFrameworkCore.Projectables.FunctionalTests/ProjectableConstructorTests.cs | Functional tests verifying SQL generation for various constructor patterns |
| tests/.../ProjectionExpressionGeneratorTests.ProjectableConstructor_*.verified.txt | Verified snapshots of generated code for generator tests |
| tests/.../ProjectableConstructorTests.Select_*.verified.txt | Verified snapshots of generated SQL for functional tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.