admin管理员组文章数量:1356045
I have a Point created from a lat/lng and stored in my database. Utilizing NetTopologySuite here. SRID 4326.
I can successfully query it for any locations in range of the provided Point.
var search = _context.Services.AsQueryable();
search = search.Where(x => x.ServiceRadius == 0
|| x.Locations.Any(y => y.GeoLocation.Distance(searchPoint) <= x.ServiceRadius));
However, when I add the OrderBy Distance it fails to translate. I swear I've done something similar to this before. Googlefoo is failing me miserably.
search = search.OrderBy(x => x.Locations.Select(y => y.GeoLocation.Distance(searchPoint)));
return search.Select(x => x.Id).ToList();
Which really should work, I would think. However, I get this error:
[wall of code] could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'.
The basic model setup is Locations that have many Services:
public class LocationModel
{
public Point? GeoLocation { get; set; }
public List<ServiceModel> Services { get; set; } = new();
}
public class ServiceModel
{
public List<LocationModel> Locations { get; set; } = new();
public int ServiceRadius { get; set; } = 0;
}
Again, removing OrderBy line it works, adding it back it fails. I definitely do not want to switch to client evaluation.
本文标签: entity framework coreOrder by distance between stored Point and provided PointStack Overflow
版权声明:本文标题:entity framework core - Order by distance between stored Point and provided Point - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743969634a2570520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论