Pass DbContext to RelationalCommandParameterObject - #36286
Merged
AndriySvyryd merged 1 commit intoJul 15, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Updates to ensure the DbContext is passed into RelationalCommandParameterObject for SQLite commands and LINQ query execution, enabling interception scenarios (e.g., OpenTelemetry).
- Pass
Dependencies.CurrentContext.Contextinstead ofnullinSqliteDatabaseCreator.Create()andHasTables() - Pass
_relationalQueryContext.Contextinstead ofnullin theCreateDbCommandmethods of several relational query enumerables
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs | Pass the current DbContext to relational command factory instead of null |
| src/EFCore.Relational/Query/Internal/SingleQueryingEnumerable.cs | Pass the query context’s DbContext into command creation |
| src/EFCore.Relational/Query/Internal/GroupBySplitQueryingEnumerable.cs | Pass the query context’s DbContext into command creation |
| src/EFCore.Relational/Query/Internal/GroupBySingleQueryingEnumerable.cs | Pass the query context’s DbContext into command creation |
Comments suppressed due to low confidence (1)
src/EFCore.Sqlite.Core/Storage/Internal/SqliteDatabaseCreator.cs:55
- Missing tests for this change: add unit or functional tests that verify the DbContext is correctly passed into RelationalCommandParameterObject for SQLite commands (e.g., in a SqliteHistoryRepository interception scenario).
Dependencies.CurrentContext.Context,
martincostello
added a commit
to martincostello/opentelemetry-dotnet-contrib
that referenced
this pull request
Jun 24, 2025
Avoid `ArgumentException` if the `DbContext` is not available in the event payload. See dotnet/efcore#36286.
- Make `DbContext` available from `RelationalCommandParameterObject` for interception with SQLite and querying enumerables. Relates to dotnet#16159
martincostello
force-pushed
the
sqllite-include-context-for-tracing
branch
from
July 4, 2025 07:10
e15b691 to
d46c152
Compare
Member
Author
|
@dotnet/efteam Could I get a review on this please? |
AndriySvyryd
approved these changes
Jul 15, 2025
Member
|
Thanks for your contribution! |
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.
Make
DbContextavailable fromRelationalCommandParameterObjectfor interception with SQLite and querying enumerables.The functionality to add the context to the interception was added originally by #16162, but the context wasn't passed through for SQLite for some reason.
I found this by chance via some changes for OpenTelemetry in open-telemetry/opentelemetry-dotnet-contrib#2829 where an exception was being thrown internally due to an assumption that the context is always non-null here and here.
It's used in
SqliteHistoryRepositoryhere, but not in the other two locations for SQLite, which this PR changes.efcore/src/EFCore.Sqlite.Core/Migrations/Internal/SqliteHistoryRepository.cs
Line 225 in 0e9f58b
While I was at it, I looked at all the other call sites for the constructor and changed any that had access to the DbContext but also just passed through null.
I haven't added any tests for this as it wasn't obvious to me where to add/edit existing tests for this. There wasn't any obvious SQLite-specific place to put tests based on reviewing the diff from #16162. I can add some if some guidance is provided on where they should go.