Skip to content
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

Fix to #17236 - Improve readability of expressions in client evaluation exception #18228

Merged
merged 1 commit into from
Oct 17, 2019

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Oct 5, 2019

Adding a new switch to ExpressionPrinter that creates simplified output for Print and verbose (i.e. what we had before this change) for PrintDebug.
Simplified output means:

  • displaying Enumerable/Queryable methods (e.g. Where, Select, Join) as extension methods
  • simplifying display of Navigation object

Also fixed minor display bugs in expression printer.

Also some changes in testing:

  • added unit tests for ExpressionPrinter,
  • DRY the "translation failed" tests,
  • "translation failed" tests no longer verify expression in the exception message and instead just make sure that right exception is thrown.

Resolves #17236

@maumar
Copy link
Contributor Author

maumar commented Oct 8, 2019

ping

@maumar
Copy link
Contributor Author

maumar commented Oct 16, 2019

@AndriySvyryd @smitpatel new version up

[ConditionalFact]
public void BinaryExpression_printed_correctly()
{
Assert.Equal("7 == 42", _expressionPrinter.Print(Expression.MakeBinary(ExpressionType.Equal, Expression.Constant(7), Expression.Constant(42))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be.
new ExpressionPrinter().Print(((Expression<Func<int, bool>>)(e => e > 42)).Body)

@maumar maumar force-pushed the fix17236 branch 2 times, most recently from 350facc to 2ffc3f4 Compare October 17, 2019 21:08
Visit(methodArguments[0]);

var methodDeclaringType = methodCallExpression.Method.DeclaringType;
if (methodDeclaringType == typeof(Queryable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought checking for extension method was sufficient to remove this specific type checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this increments the indent but check below to decrement the indent check only for simplified method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this special cases Enumerable/Queryable to be printed as:

souce
    .Method(arguments)

rather than single line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add regression test too :trollface:

expressionPrinter.Append($"MaterializeCollectionNavigation({Navigation}, ");
expressionPrinter.Visit(Subquery);
expressionPrinter.Append(")");
expressionPrinter.AppendLine("MaterializeCollectionNavigation(");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ( after the expression type. Use nameof syntax.

…on exception

Adding a new switch to ExpressionPrinter that creates simplified output for Print and verbose (i.e. what we had before this change) for PrintDebug.
Simplified output means:
- displaying extension methods as extension methods rather than regular static methods,
- simplifying display of Navigation object,
- not showing if lambda body references parameter that is out of scope.

Also fixed minor display bugs in expression printer.

Also some changes in testing:
- added unit tests for ExpressionPrinter,
- DRY the "translation failed" tests,
- "translation failed" tests no longer verify expression in the exception message and instead just make sure that right exception is thrown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve readability of expressions in client evaluation exception
3 participants