我正在尝试计算用户当前点与数据库中另一个点的距离。我写了以下代码,但出现function st_x(geography) does not exist
错误。
var pointsQueryable = _context.Points;
var points = pointsQueryable.Select(x => new PointViewModel
{
Id = x.Id,
Title = x.Title,
Address = x.Address,
Description = x.Description,
Longitude = x.Location.X,
Latitude = x.Location.Y,
Image = x.Image,
DistanceFromUser = x.Location.Distance(new Point(filter.UserLongitude, filter.UserLatitude)),
});
当然,我已经用CREATE EXTENSION postgis;
命令为数据库启用了postgis。
我使用以下代码示例在类似的项目上测试了给定的场景并且它有效:
但在我的例子中,实体的 Geom 字段定义为“Geometry”。您能否也提供您的实体类,以便问题更加清晰。
如果
NetTopologySuit
在项目中使用,以下配置可能会有所帮助。