Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace Microsoft.EntityFrameworkCore;
/// </summary>
public static class NpgsqlNetTopologySuiteDbFunctionsExtensions
{
/// <summary>
///
/// </summary>
public static bool IntersectsBbox(this DbFunctions _, Geometry geometry, Geometry anotherGeometry)
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(IntersectsBbox)));

/// <summary>
/// Returns a new geometry with its coordinates transformed to a different spatial reference system.
/// Translates to <c>ST_Transform(geometry, srid)</c>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public NpgsqlGeometryMethodTranslator(
method.ReturnType,
arguments[1].TypeMapping),

nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.IntersectsBbox) => _sqlExpressionFactory.MakePostgresBinary(
PgExpressionType.Overlaps,
arguments[1],
arguments[2]),

nameof(NpgsqlNetTopologySuiteDbFunctionsExtensions.DistanceKnn) => _sqlExpressionFactory.MakePostgresBinary(
PgExpressionType.Distance,
arguments[1],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,32 @@ public override async Task Intersection(bool async)
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task IntersectsBbox(bool async)
{
var polygon = Fixture.GeometryFactory.CreatePolygon([new Coordinate(0, 0), new Coordinate(1, 0), new Coordinate(0, 1), new Coordinate(0, 0)]);

await AssertQuery(
async,
ss => ss.Set<PolygonEntity>().Select(e => new { e.Id, IntersectsBbox = (bool?)EF.Functions.IntersectsBbox(e.Polygon, polygon) }),
ss => ss.Set<PolygonEntity>().Select(e => new { e.Id, IntersectsBbox = (e.Polygon == null ? (bool?)null : e.Polygon.EnvelopeInternal.Intersects(polygon.EnvelopeInternal)) }),
elementSorter: e => e.Id,
elementAsserter: (e, a) =>
{
Assert.Equal(e.Id, a.Id);
Assert.Equal(e.IntersectsBbox, a.IntersectsBbox);
});

AssertSql(
"""
@__polygon_1='POLYGON ((0 0, 1 0, 0 1, 0 0))' (DbType = Object)

SELECT p."Id", p."Polygon" && @__polygon_1 AS "IntersectsBbox"
FROM "PolygonEntity" AS p
""");
}

public override async Task Intersects(bool async)
{
await base.Intersects(async);
Expand Down