[英]DbGeography Intersects
I'm using DbGeography
with Entity Framework 6
using this model: 我正在使用
DbGeography
和Entity Framework 6
使用以下模型:
public class County
{
public int Id { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public DbGeography Area { get; set; }
}
I'm then trying to execute the Intersects
method like below: 然后,我尝试执行如下的
Intersects
方法:
public County GetCurrentCounty(double latitude, double longitude)
{
var point = DbGeography.PointFromText(
"POINT("
+ longitude.ToString(CultureInfo.InvariantCulture) + " "
+ latitude.ToString(CultureInfo.InvariantCulture) + ")",
4326);
var area = db.Counties.FirstOrDefault(x =>
point.Intersects(x.Area));
var area1 = db.Counties.FirstOrDefault(x =>
x.Area.Intersects(point));
}
However the query created looks like this for both methods. 但是,这两种方法创建的查询看起来都是这样。 Is there something I can do to not select the entire table and perform a query in the database instead?
有什么我可以做的,而不是选择整个表,而是在数据库中执行查询吗?
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Code] AS [Code],
[Extent1].[Area] AS [Area]
FROM [Election].[County] AS [Extent1]
Can't say what the error was but the second time it showed the correct values. 无法说出错误是什么,但是第二次显示了正确的值。 T-SQL generated by Entity Framework:
实体框架生成的T-SQL:
SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Code] AS [Code],
[Extent1].[Area] AS [Area]
FROM [Election].[County] AS [Extent1]
WHERE ([Extent1].[Area].STIntersects(@p__linq__0)) = 1
-- p__linq__0: 'POINT (10.0000000 32.0000000)' (Type = Object)
Can be tested like this manually: 可以像这样手动测试:
declare @p__linq__0 varchar(max)
set @p__linq__0 = 'POINT (10.0000000 32.0000000)'
SELECT TOP (1)
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Code] AS [Code],
[Extent1].[Area] AS [Area]
FROM [Election].[County] AS [Extent1]
WHERE ([Extent1].[Area].STIntersects(@p__linq__0)) = 1
More information can be found here: 更多信息可以在这里找到:
https://docs.microsoft.com/en-us/sql/t-sql/spatial-geometry/stintersects-geometry-data-type https://docs.microsoft.com/zh-cn/sql/t-sql/spatial-geometry/stintersects-geometry-data-type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.