将复杂查询(COS、SIN、RADIANS、ACOS)重写为 Entity-to-SQL

发布于 2024-11-13 11:36:41 字数 756 浏览 3 评论 0原文

以下存储过程检索给定纬度和经度的最近 500 个地址。许多应用程序都使用它,并且它是有用的查询之一。

是否可以用Entity-to-SQL重写?如果是这样,您能给我指出正确的方向吗(我对实体到 SQL 并不陌生)?提前致谢。

DECLARE @CntXAxis FLOAT 
DECLARE @CntYAxis FLOAT 
DECLARE @CntZAxis FLOAT 


SET @CntXAxis = COS(RADIANS(-118.4104684)) * COS(RADIANS(34.1030032)) 
SET @CntYAxis = COS(RADIANS(-118.4104684)) * SIN(RADIANS(34.1030032)) 
SET @CntZAxis = SIN(RADIANS(-118.4104684)) 

SELECT 
        500 *,
    ProxDistance = 3961 * ACOS( dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis) 
FROM 
    tbl_ProviderLocation 
WHERE 
    (3961 * ACOS( dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis) <= 10) 
ORDER BY 
    ProxDistance ASC

The following store procedure retrives nearest 500 addresses for the given latitude and longitude. Many applications use it, and it is one of the useful query.

Is it possible to rewrite with Entity-to-SQL? If so, could you please point me to the right direction (I am not new to Entity-to-SQL)? Thanks in advance.

DECLARE @CntXAxis FLOAT 
DECLARE @CntYAxis FLOAT 
DECLARE @CntZAxis FLOAT 


SET @CntXAxis = COS(RADIANS(-118.4104684)) * COS(RADIANS(34.1030032)) 
SET @CntYAxis = COS(RADIANS(-118.4104684)) * SIN(RADIANS(34.1030032)) 
SET @CntZAxis = SIN(RADIANS(-118.4104684)) 

SELECT 
        500 *,
    ProxDistance = 3961 * ACOS( dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis) 
FROM 
    tbl_ProviderLocation 
WHERE 
    (3961 * ACOS( dbo.XAxis(LAT, LONG)*@CntXAxis + dbo.YAxis(LAT, LONG)*@CntYAxis + dbo.ZAxis(LAT)*@CntZAxis) <= 10) 
ORDER BY 
    ProxDistance ASC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你而言 2024-11-20 11:36:41

如果您使用 Ms Sql Server,则可以将 SqlClient 函数与 Entity SQL

http://msdn.microsoft.com/en-us/library/bb399586.aspx" rel="nofollow">http:// /msdn.microsoft.com/en-us/library/bb399586.aspx

根据 这个这些函数也可用于 LINQ 查询。我找不到例子,但看起来很简单。

var qry = from r in mytable
select new {Acos = SqlFunctions.ACos(r.mycloumn)};

If you are using Ms Sql Server, you can use SqlClient functions with Entity SQL

http://msdn.microsoft.com/en-us/library/bb399586.aspx

According to this those functions are available for LINQ queries aswell. I couldn't find an example but it seems straightforward.

var qry = from r in mytable
select new {Acos = SqlFunctions.ACos(r.mycloumn)};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文