我正在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; }
}
然后我尝试执行如下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));
}
但是,对于这两种方法,创建的查询看起来像这样。我可以做些什么来不选择整个表并在数据库中执行查询?
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Name] AS [Name],
[Extent1].[Code] AS [Code],
[Extent1].[Area] AS [Area]
FROM [Election].[County] AS [Extent1]