【发布时间】:2018-08-14 18:29:30
【问题描述】:
我正在尝试进行查询,以便在我的 SQL 数据库中找到给定经度和纬度点(比如说 50 英里)内的所有位置。
我填充了一些帖子,在帖子表中,我有两列在创建帖子时存储经度和纬度。以下是表格的外观:
我浏览了许多有关如何尝试实现此功能的示例,但似乎它们根本不起作用。我通过研究得知 ASP.NET Core 不支持DbGeography,其他文章只是过时了。
找到了这个article,但它使用了DbGeography,所以这不起作用。
在 GitHub 上找到了这个:here 我只是不知道这是否可行。
仅供参考,这是我的 Post 模型的外观:
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public double Lat { get; set; }
public double Lng { get; set; }
public DateTime Created { get; set; }
public Category Category { get; set; }
public int CategoryId { get; set; }
// Other navigation properties...
}
这就是我现在进行查询以在前端的 Google 地图上显示点的方式:
public class HomeController : Controller
{
private readonly ApplicationDbContext _context;
public HomeController(ApplicationDbContext context)
{
_context = context;
}
[HttpGet]
public JsonResult GetGalleryLocations()
{
var data = _context.Posts
.Include(c => c.Category)
.ToList();
return Json(data);
}
}
有人对如何实现这样的查询有任何见解吗?
【问题讨论】:
-
您需要执行直接 SQL 查询。
标签: c# asp.net entity-framework geocoding asp.net-core-2.0