我有以下POCO;
public class Trader : AuditableEntity
{
public string Name { get; set; }
public string Telephone { get; set; }
public string Email { get; set; }
public string Website { get; set; }
public List<Address> Addresses { get; set; }
}
public class Address : AuditableEntity
{
public Trader Trader { get; set; }
/* reduce for brevity*/
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public IPoint Location { get; set; }
}
当前的需求是能够基于纬度,经度和距离的传递,使用List<Trader>
从搜索中拉回NetTopologySuite
。目前,我们的服务如下:
var currentLocation = new Point((double)customerLongitude, (double)customerLatitude) { SRID = 4326 };
var traders = context.Where<Trader>(x => x.Addresses.Any(y => y.Location.IsWithinDistance(currentLocation, distanceFromCustomer)));
在迁移到EntityFrameworkCore
2.2之前,将使用存储过程。在存储过程中,我可以动态返回交易者lat long与传入的lat long之间的距离以及返回数据;
Distance = (@GEO1.STDistance(geography::Point(ISNULL(Latitude,0.000000),ISNULL(Longitude,0.000000), 4326)))
我是否可以使用linq进行动态地理位置定位并选择距离,就像存储的proc并将其有效地添加到返回中一样?