Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ public virtual Expression Translate(SyntaxNode node, SemanticModel semanticModel

// Perform data flow analysis to detect all variables flowing into the query (e.g. captured variables)
_dataFlowsIn.Clear();
foreach (var flowsIn in _semanticModel.AnalyzeDataFlow(node).DataFlowsIn)
var dataFlow = _semanticModel.AnalyzeDataFlow(node);

// Analysis fails when the query is the receiver of an instance call (dotnet/roslyn#86099)
for (var parent = node.Parent; !dataFlow.Succeeded && parent is ExpressionSyntax; parent = parent.Parent)
{
dataFlow = _semanticModel.AnalyzeDataFlow(parent);
}

foreach (var flowsIn in dataFlow.DataFlowsIn)
{
_dataFlowsIn[flowsIn] = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,23 @@ public virtual Task Terminating_with_cancellation_token()
CancellationToken token = source.Token;
Assert.Equal("Blog1", (await context.Blogs.Where(b => b.Id == 8).FirstOrDefaultAsync(token)).Name);
Assert.Null(await context.Blogs.Where(b => b.Id == 7).FirstOrDefaultAsync(token));
""");

[Fact] // #37961
public virtual Task Terminating_with_ConfigureAwait()
=> Test(
"""
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
Assert.Equal("Blog1", (await context.Blogs.Where(b => b.Id == 8).FirstOrDefaultAsync(token).ConfigureAwait(false)).Name);
""");

[Fact]
public virtual Task Terminating_followed_by_instance_method_call()
=> Test(
"""
var id = 8;
Assert.Equal("1", context.Blogs.Count(b => b.Id == id).ToString());
""");

#endregion Reducing terminating operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,32 @@ FROM [Blogs] AS [b]
""");
}

public override async Task Terminating_with_ConfigureAwait()
{
await base.Terminating_with_ConfigureAwait();

AssertSql(
"""
SELECT TOP(1) [b].[Id], [b].[Name], [b].[Json]
FROM [Blogs] AS [b]
WHERE [b].[Id] = 8
""");
}

public override async Task Terminating_followed_by_instance_method_call()
{
await base.Terminating_followed_by_instance_method_call();

AssertSql(
"""
@id='8'

SELECT COUNT(*)
FROM [Blogs] AS [b]
WHERE [b].[Id] = @id
""");
}

#endregion Reducing terminating operators

#region SQL expression quotability
Expand Down
Loading