Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/EFCore.PG/Internal/EnumerableMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static class EnumerableMethods

public static MethodInfo All { get; }

// public static MethodInfo AnyWithoutPredicate { get; }
public static MethodInfo AnyWithoutPredicate { get; }

public static MethodInfo AnyWithPredicate { get; }

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

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

AnyWithPredicate = GetMethod(
nameof(Enumerable.Any), 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public NpgsqlByteArrayMethodTranslator(ISqlExpressionFactory sqlExpressionFactor
_sqlExpressionFactory.Constant(0));
}

if (method.GetGenericMethodDefinition().Equals(EnumerableMethods.AnyWithoutPredicate))
{
return _sqlExpressionFactory.GreaterThan(
_sqlExpressionFactory.Function(
"length",
[arguments[0]],
nullable: true,
argumentsPropagateNullability: TrueArrays[1],
typeof(int)),
_sqlExpressionFactory.Constant(0));
}

if (method.GetGenericMethodDefinition().Equals(EnumerableMethods.FirstWithoutPredicate))
{
return _sqlExpressionFactory.Convert(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.EntityFrameworkCore.TestModels.BasicTypesModel;

namespace Microsoft.EntityFrameworkCore.Query.Translations;

public class ByteArrayTranslationsNpgsqlTest : ByteArrayTranslationsTestBase<BasicTypesQueryNpgsqlFixture>
Expand Down Expand Up @@ -98,6 +100,19 @@ public override async Task SequenceEqual()
""");
}

[ConditionalFact]
public virtual async Task Any()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW I'll "promote" this test to the EF test suite later as it's not very PG-specific.

{
await AssertQuery(ss => ss.Set<BasicTypesEntity>().Where(e => e.ByteArray.Any()));

AssertSql(
"""
SELECT b."Id", b."Bool", b."Byte", b."ByteArray", b."DateOnly", b."DateTime", b."DateTimeOffset", b."Decimal", b."Double", b."Enum", b."FlagsEnum", b."Float", b."Guid", b."Int", b."Long", b."Short", b."String", b."TimeOnly", b."TimeSpan"
FROM "BasicTypesEntities" AS b
WHERE length(b."ByteArray") > 0
""");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Loading