Skip to content

Comments

Add support for projectable constructors#155

Draft
PhenX wants to merge 8 commits intocopilot/support-classic-methods-transformationfrom
feature/projectable-constructor
Draft

Add support for projectable constructors#155
PhenX wants to merge 8 commits intocopilot/support-classic-methods-transformationfrom
feature/projectable-constructor

Conversation

@PhenX
Copy link
Collaborator

@PhenX PhenX commented Feb 22, 2026

No description provided.

Copy link

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

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 ProjectableAttribute to 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 NewExpression nodes 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.

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.

1 participant