Table of Contents

Class GeoCoordinateExpressions

Namespace
Trellis.EntityFrameworkCore
Assembly
Trellis.EntityFrameworkCore.dll

Builds provider-translatable expressions for geographic bounding and spherical distance queries.

public static class GeoCoordinateExpressions
Inheritance
GeoCoordinateExpressions
Inherited Members

Remarks

The configured provider must translate the resulting arithmetic and Math calls. Translation failures propagate; these helpers never compile an expression or fall back to client evaluation.

Methods

DistanceMetersTo<TEntity>(Expression<Func<TEntity, double>>, Expression<Func<TEntity, double>>, GeoCoordinate)

Builds a spherical haversine-distance expression in meters.

public static Expression<Func<TEntity, double>> DistanceMetersTo<TEntity>(Expression<Func<TEntity, double>> latitudeSelector, Expression<Func<TEntity, double>> longitudeSelector, GeoCoordinate origin) where TEntity : class

Parameters

latitudeSelector Expression<Func<TEntity, double>>

Selects a latitude in decimal degrees.

longitudeSelector Expression<Func<TEntity, double>>

Selects a longitude in decimal degrees.

origin GeoCoordinate

The fixed query origin.

Returns

Expression<Func<TEntity, double>>

An expression suitable for projection, ordering, filtering, or a computed SeekDefinition<T, TState>.

Type Parameters

TEntity

The query entity or projection type.

Remarks

Uses the same mean Earth radius and spherical model as DistanceMetersTo(GeoCoordinate). The database provider determines the final floating-point precision.

Exceptions

ArgumentNullException

A selector or origin is null.

WithinBounds<TEntity>(Expression<Func<TEntity, double>>, Expression<Func<TEntity, double>>, GeoBounds)

Builds the conservative one-or-two-box prefilter represented by bounds.

public static Expression<Func<TEntity, bool>> WithinBounds<TEntity>(Expression<Func<TEntity, double>> latitudeSelector, Expression<Func<TEntity, double>> longitudeSelector, GeoBounds bounds) where TEntity : class

Parameters

latitudeSelector Expression<Func<TEntity, double>>

Selects a latitude in decimal degrees.

longitudeSelector Expression<Func<TEntity, double>>

Selects a longitude in decimal degrees.

bounds GeoBounds

Validated spherical search bounds.

Returns

Expression<Func<TEntity, bool>>

An inclusive predicate over the stored latitude and longitude components.

Type Parameters

TEntity

The query entity or projection type.

Remarks

This predicate can include false positives. Use WithinRadius<TEntity>(Expression<Func<TEntity, double>>, Expression<Func<TEntity, double>>, GeoBounds) when exact spherical-radius membership is required.

Exceptions

ArgumentNullException

A selector or bounds is null.

WithinRadius<TEntity>(Expression<Func<TEntity, double>>, Expression<Func<TEntity, double>>, GeoBounds)

Builds a conservative box prefilter followed by an exact spherical-distance predicate.

public static Expression<Func<TEntity, bool>> WithinRadius<TEntity>(Expression<Func<TEntity, double>> latitudeSelector, Expression<Func<TEntity, double>> longitudeSelector, GeoBounds bounds) where TEntity : class

Parameters

latitudeSelector Expression<Func<TEntity, double>>

Selects a latitude in decimal degrees.

longitudeSelector Expression<Func<TEntity, double>>

Selects a longitude in decimal degrees.

bounds GeoBounds

Validated center, radius, and conservative boxes.

Returns

Expression<Func<TEntity, bool>>

An expression matching rows whose computed distance is at most the configured radius.

Type Parameters

TEntity

The query entity or projection type.

Remarks

The provider evaluates the inclusive distance comparison. Its transcendental functions can round differently from DistanceMetersTo(GeoCoordinate) at an exactly represented boundary; include an application tolerance in RadiusMeters when that distinction matters.

Exceptions

ArgumentNullException

A selector or bounds is null.