Skip to content

Fix precompiled queries that are the receiver of an instance method call - #39331

Open
nurullahturkoglu wants to merge 1 commit into
dotnet:mainfrom
nurullahturkoglu:fix/precompiled-configureawait-37961
Open

nurullahturkoglu wants to merge 1 commit into
dotnet:mainfrom
nurullahturkoglu:fix/precompiled-configureawait-37961

Conversation

@nurullahturkoglu

Copy link
Copy Markdown
Contributor

Fixes #37961

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

I posted the plan in #37961 (comment) but haven't heard back from the team yet, so the second box is unchecked.

Description

CSharpToLinqTranslator.Translate gets the captured variables from AnalyzeDataFlow(node).DataFlowsIn. When the query is the receiver of an instance method call, such as .ConfigureAwait(false) or .ToString(), Roslyn returns Succeeded == false with an empty DataFlowsIn, and the translator then fails with "unknown identifier". It's a Roslyn regression from dotnet/roslyn#67913 (4.5 works, 4.7 doesn't), reported in dotnet/roslyn#86099 with a fix in dotnet/roslyn#86100.

When the analysis fails, the translator now retries it on the enclosing expressions until one succeeds. A wider region can bring in variables the query doesn't use, but _dataFlowsIn is only looked up for symbols the query references, so those entries are ignored. Once the Roslyn fix is picked up, the retry is no longer needed for this case.

The synchronous case, e.g. context.Blogs.Count(b => b.Id == id).ToString(), fails the same way, so it's covered as well.

Testing

I added Terminating_with_ConfigureAwait (the case from the issue) and Terminating_followed_by_instance_method_call (synchronous) to PrecompiledQueryRelationalTestBase, with SQL Server overrides.

Without the fix, both tests fail on SQLite ("unknown identifier 'token'" and "'id'") and on SQL Server. With the fix, the SQLite and SQL Server precompiled query tests pass (SQL Server ran against a local Linux container on macOS), as does EFCore.Design.Tests.

I haven't run the full functional test suites, and I haven't run anything on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding .ConfigureAwait() to async query causes precompiled query generation to fail

1 participant