我有一些记录,我试图根据距离查询EF 6。我有一个地理专栏,并在.NET中使用过DbGeography类。我执行查询时收到Null Reference Exception。想法?
方法
NullReferenceException
错误堆栈
在KittyHawk.Domain.Services.LocationService。<> c__DisplayClass3_0.b__0(LocationEntity l)在D:\ Development \ manteo \ KittyHawk.Domain \ Services \ LocationService.cs:第40行 at System.Linq.Enumerable.WhereSelectEnumerableIterator
public IList<Location> GetAllByCoordinates(double longitude, double latitude, double distance) { var geoPoint = DbGeography.PointFromText($"POINT({longitude} {latitude})", 4326); return _repo.GetAll() .Select(l => new Location { Id = l.Id, Longitude = l.Longitude, Latitude = l.Latitude, Elevation = l.Elevation, Distance = l.Geography.Distance(geoPoint).Value }).ToList(); }
1..ctor(IEnumerable2.MoveNext() at System.Collections.Generic.List
1 source) 在KittyHawk.Domain.Services.LocationService.GetAllByCoordinates(双经度,双纬度,双倍距离)在D:\ Development \ manteo \ KittyHawk.Domain \ Services \ LocationService.cs:第39行 在KittyHawk.Controllers.LocationController.GetNearbyLocations(双经度,双纬度,双倍距离)在D:\ Development \ manteo \ KittyHawk \ Controllers \ LocationController.cs:第39行 在lambda_method(Closure,Object,Object []) 在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor。&lt;&gt; c__DisplayClass10.b__9(Object instance,Object [] methodParameters) 在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance,Object [] arguments) 在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2 arguments,CancellationToken cancellationToken)
答案 0 :(得分:0)
检查以确保geoPoint不为空。然后,确保所有位置点都有一个长/纬度。我觉得你的数据库中有一些位置可以拥有它们吗?