Need for an RPC friendly query output

Open
#20,563 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, sql
Domain
databases

Research direction

Start at the ToQueryString entry point and trace the SQL Server query-output path, paying attention to how parameter declarations and query text are assembled. Done means a separate output view can represent the executed query as an sp_executesql RPC-style wrapper while retaining the existing readable output.

Written by the indexing model from the issue text.

Description

area-query customer-reported

EF runs parameterised queries against SQL Server, using RPC statements.
The current output of ToQueryString outputs the query being run but prefixes the query with the parameter declarations

DECLARE @foo int = 99
SELECT foo FROM dbo.myTable WHERE id = @foo

This can be copied and run in Management Studio of Azure Data Studio, but its not replicating the query run by EF because the query text is different and the parameter is not being passed in as a parameter to an RPC call. Its just executing a single batch including the parameter.

The way to solve this is to 1. get SSMS to be able to run RPC statements (it sort for can for Always Encrypted connections but that won't work here) 2. output the text as

DECLARE @foo int = 99
exec sp_executesql N'SELECT foo FROM dbo.myTable where id = @foo', N'@foo int', @foo

Whilst the outer text looks different this is just a wrapper and doesn't do anything. The query being executed really is whats passed to sp_executesql which is matches what EF has executed.
This is what SQL profiler has done for years.

It makes the query less readable in Management Studio and thus having a second output that provides this view if people are caring about performance and understanding the query plans that are being used by the EF queries.

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.