Skip to content

Commit 403572f

Browse files
committed
Translate Any over bytea
1 parent 8b793ef commit 403572f

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/EFCore.PG/Internal/EnumerableMethods.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal static class EnumerableMethods
1010

1111
public static MethodInfo All { get; }
1212

13-
// public static MethodInfo AnyWithoutPredicate { get; }
13+
public static MethodInfo AnyWithoutPredicate { get; }
1414

1515
public static MethodInfo AnyWithPredicate { get; }
1616

@@ -259,8 +259,9 @@ static EnumerableMethods()
259259
nameof(Enumerable.All), 1,
260260
types => [typeof(IEnumerable<>).MakeGenericType(types[0]), typeof(Func<,>).MakeGenericType(types[0], typeof(bool))]);
261261

262-
// AnyWithoutPredicate = GetMethod(nameof(Enumerable.Any), 1,
263-
// types => new[] { typeof(IEnumerable<>).MakeGenericType(types[0]) });
262+
AnyWithoutPredicate = GetMethod(
263+
nameof(Enumerable.Any), 1,
264+
types => [typeof(IEnumerable<>).MakeGenericType(types[0])]);
264265

265266
AnyWithPredicate = GetMethod(
266267
nameof(Enumerable.Any), 1,

src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlByteArrayMethodTranslator.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public NpgsqlByteArrayMethodTranslator(ISqlExpressionFactory sqlExpressionFactor
4646
// Note: we only translate if the array argument is a column mapped to bytea. There are various other
4747
// cases (e.g. Where(b => new byte[] { 1, 2, 3 }.Contains(b.SomeByte))) where we prefer to translate via
4848
// regular PostgreSQL array logic.
49+
if (method.GetGenericMethodDefinition().Equals(EnumerableMethods.AnyWithoutPredicate))
50+
{
51+
return _sqlExpressionFactory.GreaterThan(
52+
_sqlExpressionFactory.Function(
53+
"length",
54+
[arguments[0]],
55+
nullable: true,
56+
argumentsPropagateNullability: TrueArrays[1],
57+
typeof(int)),
58+
_sqlExpressionFactory.Constant(0));
59+
}
60+
4961
if (method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains))
5062
{
5163
var source = arguments[0];

0 commit comments

Comments
 (0)