C# 使用IQueryable查找半径为另一个坐标的点
我将用户存储在一个设置了纬度和经度的数据库中。我想在我的服务层中编写一个过滤器方法 我们正在使用ASP.NETMVC和存储库模式。现在我们将在SQLServer中使用实体框架。以后可能会切换到Azure或Amazon 我的筛选方法如下所示:C# 使用IQueryable查找半径为另一个坐标的点,c#,asp.net-mvc,algorithm,iqueryable,geography,C#,Asp.net Mvc,Algorithm,Iqueryable,Geography,我将用户存储在一个设置了纬度和经度的数据库中。我想在我的服务层中编写一个过滤器方法 我们正在使用ASP.NETMVC和存储库模式。现在我们将在SQLServer中使用实体框架。以后可能会切换到Azure或Amazon 我的筛选方法如下所示: public static IQueryable<IPerson> InRadius(this IQueryable<IPerson> query, Coordinate center, double radius)
public static IQueryable<IPerson> InRadius(this IQueryable<IPerson> query, Coordinate center, double radius)
{
return (from u in query
where
(Math.Pow(u.Location.Coordinate.Latitude - center.Latitude, 2) +
Math.Pow(u.Location.Coordinate.Longitude - center.Longitude, 2)) < Math.Pow(radius, 2)
select u);
}
radius中的公共静态IQueryable(此IQueryable查询,坐标中心,双半径)
{
返回(来自查询中的u)
哪里
(Math.Pow(u.Location.Coordinate.Latitude-center.Latitude,2)+
Math.Pow(u.Location.Coordinate.Longitude-center.Longitude,2))
看看这个,有点不对劲。这是一个正规三角的公式。这是假设半径的测量值与纬度和经度的单位相同
我对该代码有几个问题:
Math.Pow(double,double)
传递到数据库Math.Pow
应该由实体框架映射到sql中的appropiate方法Math.Pow
应该由实体框架映射到sql中的appropiate方法POWER
,但您必须尝试并确定它Math.Pow(someExpression,2)
更改为someExpression*someExpression
。这肯定会在数据库上执行POWER
,但您必须尝试并确定它Math.Pow(someExpression,2)
更改为someExpression*someExpression
。这肯定会在数据库上执行我看到了地球的算法,它们有正弦和余弦,等等。我需要写出这些的函数,这样它们才能被映射吗?任何形式的计算,如果从头开始写的话,都可以转换成sql?我正在看地球的算法,它们有sin和cosine等。我需要为它们写函数,这样它们才能被映射吗?如果从头开始编写,任何形式的计算都可以转换为sql?