-
Notifications
You must be signed in to change notification settings - Fork 256
Translate List<T> operations to PG array #1185
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace Npgsql.EntityFrameworkCore.PostgreSQL | ||
| { | ||
| internal static class TypeExtensions | ||
| { | ||
| internal static bool IsGenericList(this Type type) | ||
| => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>); | ||
|
|
||
| internal static bool IsArrayOrGenericList(this Type type) | ||
| => type.IsArray || type.IsGenericList(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
|
|
@@ -127,9 +128,11 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCall) | |
| if (visited != null) | ||
| return visited; | ||
|
|
||
| // TODO: Handle List<> | ||
| if (methodCall.Arguments.Count > 0 && methodCall.Arguments[0].Type.IsArray) | ||
| if (methodCall.Arguments.Count > 0 && ( | ||
| methodCall.Arguments[0].Type.IsArray || methodCall.Arguments[0].Type.IsGenericList())) | ||
|
Contributor
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. nit: Having all on a single line would be better, but it's up to you. Is it perf sensitive?
Member
Author
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. I guess I'm starting to make more of an effort to respect 120 chars width :) Must be more bad EF influence...! But in this case it seems to express the logical structure better (or and and)...
You mean because of the double |
||
| { | ||
| return VisitArrayMethodCall(methodCall.Method, methodCall.Arguments); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
@@ -183,7 +186,7 @@ arguments[1] is LambdaExpression wherePredicate && | |
| arguments[1] is LambdaExpression wherePredicate && | ||
| wherePredicate.Body is MethodCallExpression wherePredicateMethodCall && | ||
| wherePredicateMethodCall.Method.IsClosedFormOf(Contains) && | ||
| wherePredicateMethodCall.Arguments[0].Type.IsArray && | ||
| wherePredicateMethodCall.Arguments[0].Type.IsArrayOrGenericList() && | ||
| wherePredicateMethodCall.Arguments[1] is ParameterExpression parameterExpression && | ||
| parameterExpression == wherePredicate.Parameters[0]) | ||
| { | ||
|
|
@@ -207,7 +210,7 @@ wherePredicateMethodCall.Arguments[1] is ParameterExpression parameterExpression | |
| arguments[1] is LambdaExpression wherePredicate && | ||
| wherePredicate.Body is MethodCallExpression wherePredicateMethodCall && | ||
| wherePredicateMethodCall.Method.IsClosedFormOf(Contains) && | ||
| wherePredicateMethodCall.Arguments[0].Type.IsArray && | ||
| wherePredicateMethodCall.Arguments[0].Type.IsArrayOrGenericList() && | ||
| wherePredicateMethodCall.Arguments[1] is ParameterExpression parameterExpression && | ||
| parameterExpression == wherePredicate.Parameters[0]) | ||
| { | ||
|
|
||
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.
The name could be simplified:
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.
This was just to make it explicit that non-generic lists aren't covered.