-
Notifications
You must be signed in to change notification settings - Fork 934
Fix constant value in function cached in LINQ query #1540
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,19 +109,23 @@ protected override Expression VisitConstant(ConstantExpression expression) | |
{ | ||
_string.Append("NULL"); | ||
} | ||
else | ||
else if (expression.Value is IQueryable) | ||
{ | ||
var value = expression.Value as IEnumerable; | ||
if (value != null && !(value is string) && !(value is IQueryable)) | ||
{ | ||
_string.Append("{"); | ||
_string.Append(String.Join(",", value.Cast<object>())); | ||
_string.Append("}"); | ||
} | ||
else | ||
_string.Append(expression.Value); | ||
} | ||
else if (expression.Value is IEnumerable enumerable && !(enumerable is string)) | ||
{ | ||
_string.Append("{"); | ||
foreach (var value in enumerable) | ||
{ | ||
_string.Append(expression.Value); | ||
_string.Append(value).Append("#").Append(value.GetHashCode()).Append(","); | ||
} | ||
|
||
_string.Append("}"); | ||
} | ||
else | ||
{ | ||
_string.Append(expression.Value).Append("#").Append(expression.Value.GetHashCode()); | ||
} | ||
} | ||
|
||
|
@@ -163,20 +167,21 @@ protected override Expression VisitMethodCall(MethodCallExpression expression) | |
{ | ||
var old = insideSelectClause; | ||
|
||
switch (expression.Method.Name) | ||
{ | ||
case "First": | ||
case "FirstOrDefault": | ||
case "Single": | ||
case "SingleOrDefault": | ||
case "Select": | ||
case "GroupBy": | ||
insideSelectClause = true; | ||
break; | ||
default: | ||
insideSelectClause = false; | ||
break; | ||
} | ||
if (expression.Method.DeclaringType?.Namespace == "System.Linq") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For putting what in it? All the point of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I've checked that my suggestion does not work. |
||
switch (expression.Method.Name) | ||
{ | ||
case "First": | ||
case "FirstOrDefault": | ||
case "Single": | ||
case "SingleOrDefault": | ||
case "Select": | ||
case "GroupBy": | ||
insideSelectClause = true; | ||
break; | ||
default: | ||
insideSelectClause = false; | ||
break; | ||
} | ||
|
||
Visit(expression.Object); | ||
_string.Append('.'); | ||
|
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.
I have a hard time conceiving a valid query having objects instances instead of primitive types in a list/array. Are you sure this is useful to change the enumerable case too?