1

我正在尝试将 NetTopologySuite 与 EF Core 2.2.6 一起使用来执行地理搜索。

我已成功Point向我的模型添加了位置,EF Core可以读取和写入此属性。

但是,当我尝试将此谓词添加到我的查询中时,我发现了两个问题:

query = query.Where(x => x.Foo.Bar.Location.Distance(new Point(longitude, latitude) { SRID = 4326 }) <= distance);
  1. 执行NullReferenceException查询时抛出异常。
   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. 如果我在 SQL Profiler 中查看已执行的 SQL,则不会添加任何 WHERE 子句。

我已经检查过的事情:

  1. 我有UseNetTopologySuite()我的OnConfiguring覆盖。
  2. 我使用NetTopologySuite.Core的是 1.15.3 版本,这是 EF Core 2.2.6 的合适版本。
4

0 回答 0