1
我在我的数据库中有一个包含地理位置的表格。我想编写一个函数来查找最接近点的位置。我在NHibernate试过这个:按NHibernate中的函数结果排序?
public Location GetClosestLocation(double latitude, double longitude)
{
var closest = Session.QueryOver<Location>()
.OrderBy(location =>
(location.Latitude - latitude) +
(location.Longitude - longitude))
.Asc.SingleOrDefault();
return closest;
}
但它不起作用 - 我得到一个运行时错误。
我能做些什么来返回最近的位置?是否有可能通过NHibernate的简单函数的结果进行排序?
谢谢,我想是这样的。给任何其他发现这个问题的人留下一个提示 - 记住拿走绝对的距离! – Oliver