Conversation
…nsions; add VendorTests project Agent-Logs-Url: https://github.com/EFNext/EntityFrameworkCore.Projectables/sessions/a64490fa-46e4-49f0-8bf9-d507f70ef85d Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
…od, remove duplicate test Agent-Logs-Url: https://github.com/EFNext/EntityFrameworkCore.Projectables/sessions/a64490fa-46e4-49f0-8bf9-d507f70ef85d Co-authored-by: PhenX <42170+PhenX@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update EntityFrameworkCore.Projectables to fix bulk operation issues
Fix EFCore.BulkExtensions compatibility: shadow Apr 11, 2026
_queryContextFactory in CustomQueryCompiler
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the runtime integration layer where Projectables’ CustomQueryCompiler : QueryCompiler breaks EFCore.BulkExtensions’ reflection-based DbContext discovery, causing BatchDelete/BatchUpdate to throw TargetException.
Changes:
- Shadow
QueryCompiler’s private_queryContextFactoryfield onCustomQueryCompilersoGetField(...).GetValue(...)works when starting reflection from the derived type. - Add a new
VendorTeststest project to validate EFCore.BulkExtensions compatibility against SQLite in-memory. - Add central package version for
EFCore.BulkExtensionsand include the new test project in the solution.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EntityFrameworkCore.Projectables/Infrastructure/Internal/CustomQueryCompiler.cs | Adds a shadow _queryContextFactory field to restore EFCore.BulkExtensions reflection compatibility. |
| tests/EntityFrameworkCore.Projectables.VendorTests/EntityFrameworkCore.Projectables.VendorTests.csproj | New vendor test project targeting net8.0 with BulkExtensions + SQLite. |
| tests/EntityFrameworkCore.Projectables.VendorTests/TestContext.cs | Test entity + SQLite in-memory DbContext configured with UseProjectables(). |
| tests/EntityFrameworkCore.Projectables.VendorTests/EFCoreBulkExtensionsCompatibilityTests.cs | Verifies BatchUtil.GetDbContext and batch operations don’t fail due to reflection (TargetException). |
| EntityFrameworkCore.Projectables.sln | Adds the new VendorTests project to the solution. |
| Directory.Packages.props | Adds central version entry for EFCore.BulkExtensions 8.0.4. |
tests/EntityFrameworkCore.Projectables.VendorTests/TestContext.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PhenX
approved these changes
Apr 11, 2026
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.
Projectables 3.x breaks EFCore.BulkExtensions'
BatchDelete/BatchUpdatewithTargetException: Non-static method requires a targeton any project using both libraries.Root Cause
BatchUtil.GetDbContextresolves theDbContextvia this reflection chain:C# reflection does not surface private fields declared on a base class when
GetFieldis called on a derived type. With plain EF Core,compiler.GetType()isQueryCompiler— the exact declaring type — so the lookup succeeds. With Projectables,compiler.GetType()isCustomQueryCompiler : QueryCompiler, soGetField("_queryContextFactory")returnsnulland the nextGetValue(null)throws.Fix
CustomQueryCompiler— shadow fieldAdded a
private readonly IQueryContextFactory _queryContextFactoryfield directly onCustomQueryCompiler, initialized in the constructor with the same instance passed to the base. This makes the field visible toGetFieldwhen the lookup starts from the derived type:New
VendorTestsprojectAdded
tests/EntityFrameworkCore.Projectables.VendorTests(net8.0, EFCore.BulkExtensions 8.0.4 + SQLite in-memory) with tests that:BatchUtil.GetDbContext(query)does not throw and returns the expected contextBatchDeleteAsync/BatchUpdateAsyncdo not throw aTargetException