将复杂查询(COS、SIN、RADIANS、ACOS)重写为 Entity-to-SQL
以下存储过程检索给定纬度和经度的最近 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 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 查询。我找不到例子,但看起来很简单。
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.