1

I'm trying to use NetTopologySuite with EF Core 2.2.6 to perform a geographical search.

I've successfully added a location Point to my model, and EF Core can read and write this property.

However, when I try to add this predicate to my query I see two problems:

query = query.Where(x => x.Foo.Bar.Location.Distance(new Point(longitude, latitude) { SRID = 4326 }) <= distance);
  1. A NullReferenceException exception is thrown when the query is executed.
   at lambda_method(Closure , TransparentIdentifier`2 )
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  1. If I look at the executed SQL in SQL Profiler, no WHERE clause is being added.

Thing I've already checked:

  1. I have UseNetTopologySuite() in my OnConfiguring override.
  2. I'm using NetTopologySuite.Core version 1.15.3, which is the appropriate version for EF Core 2.2.6.
James
  • 2,404
  • 2
  • 28
  • 33

0 Answers0