繁体   English   中英

实体框架空间查询引发Null参考异常

[英]Entity Framework Spatial Query Throws Null Reference Exception

我有一些记录正在尝试根据距离使用EF 6查询。 我有一个地理专栏,并在.NET中使用了DbGeography类。 执行查询时,出现Null引用异常。 有想法吗?

方法

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();
    }

错误堆栈

在KittyHawk.Domain.Services.LocationService。<> c__DisplayClass3_0.b__0(LocationEntity l)在System.Linq.Enumerable.WhereSelectEnumerableIterator 2.MoveNext() at System.Collections.Generic.List D:\\ Development \\ manteo \\ KittyHawk.Domain \\ Services \\ LocationService.cs:line 40中2.MoveNext() at System.Collections.Generic.List KittyHawk.Domain.Services.LocationService.GetAllByCoordinates(Doublelongitude,Double latitude 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1源)的System.Collections.Generic.List处。 ,则是D:\\ Development \\ manteo \\ KittyHawk.Domain \\ Services \\ LocationService.cs:第39行,位于D:\\ Development \\ manteo \\ KittyHawk.Controllers.LocationController.GetNearbyLocations(D:\\ Doubletitude,Double Latitude,Double distance)中KittyHawk \\ Controllers \\ LocationController.cs:System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.lambda_method(Closure,Object,Object [])的第39行。<> c__DisplayClass10.b__9(系统处的Object实例,Object [] methodParameters) .Web.Http.Controllers.ReflectedHttpActionDe System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2 arguments,CancellationToken cancelledToken处的scriptor.ActionExecutor.Execute(对象实例,Object []参数)

检查以确保geoPoint不是null。 然后,请确保您所有的定位点都长/纬度。 我觉得您的数据库中确实有一些位置吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM