-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DebugView for query and simple way to get SQL from an EF LINQ query #19324
Conversation
Fixes #6482 Given a query like: ```C# var query = context.Set<Customer>().Where(c => c.City == city); ``` The SQL that will be generated for this query can be obtained by: ```C# var queryString = query.ToQueryString(); ``` and looks like this: ```sql -- @__city_0='London' (Size = 4000) SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region] FROM [Customers] AS [c] WHERE [c].[City] = @__city_0 ``` Also, this is used to provide a `DebugView` with both the nicely printed expression: and the generated SQL:
Yay! Maybe this time? |
public string ToQueryString() | ||
{ | ||
var sqlQuery = _querySqlGeneratorFactory.Create().GetSqlQuery( | ||
(SelectExpression)new InExpressionValuesExpandingExpressionVisitor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract and DRY as this is likely to change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that, but then reverted since it was more lines of code. But will do it since you think it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fewer LoC isn't always better 😃
Would it be possible to get
instead of
Most often when i look for the query string, i want to copy paste it into SSMS to get an actual execution plan which requires manual fixup of the parameters. |
@Suchiman Great suggestion! |
@Suchiman @ErikEJ We discussed today--see #19334 (comment) |
@ajcvickers Great news! |
This looks amazing! Are there any thoughts as to when this will ship? |
In Daily builds now, will ship in November 2020 |
So pleased to hear it! Out curiousity, how come it's not going out until November? That's a little while from now. Is it part of the next major release of EF core? |
@johnnyreilly For business reasons, the EF Core release schedule aligns with that of .NET Core. |
Fixes #6482
Given a query like:
The SQL that will be generated for this query can be obtained by:
and looks like this:
Also, this is used to provide a
DebugView
with both the nicely printed expression:and the generated SQL: