where 子句中的 MonoRail ActiveRecord/NHibernate 计算
我试图让企业在用户的一定英里范围内,使用公式来获取企业的纬度/经度和用户的纬度/经度之间的距离。代码如下:
var criteria = DetachedCriteria.For<Core.Models.Business>(); criteria.Add(Restrictions.Le(String.Format(@"(3959*acos(cos(radians({0}))*cos(radians(Latitude))*cos(radians(Longitude)-radians({1}))
+sin(radians({0}))*sin(radians(Latitude))))", coordinates.Latitude, coordinates.Longitude), radiusInMiles));
问题是 ActiveRecord/NHibernate 的 Restrictions.Le 方法需要第一个参数的属性名称,因此我无法在其中放置公式。我该怎么做这样的事情?
谢谢! 贾斯汀
I'm trying to get businesses within a certain number of miles of a user, using a formula to get the distance between the lat/long of the business and the lat/long of the user. Here is the code:
var criteria = DetachedCriteria.For<Core.Models.Business>(); criteria.Add(Restrictions.Le(String.Format(@"(3959*acos(cos(radians({0}))*cos(radians(Latitude))*cos(radians(Longitude)-radians({1}))
+sin(radians({0}))*sin(radians(Latitude))))", coordinates.Latitude, coordinates.Longitude), radiusInMiles));
The problem is that ActiveRecord/NHibernate's Restrictions.Le method expects a property name for the first parameter so I can't put a formula in there. How would I do something like this?
Thanks!
Justin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
Expression.Sql
。几个示例:Try using
Expression.Sql
. A couple of examples: