使用 Entity Framework 5,可以在 Linq 查询中使用 SQL Server Spatial 过程。
例如,使用 DbGeography 对象,您可以使用“Buffer()”方法,该方法将转换为 SQL Server 中的 STBuffer。同样,Intersects() 将转换为 STIntersects。
这是一个有效的示例查询:
var point = DbGeography.FromText(string.Format("POINT({1} {0})", latitude, longitude), 4326);
var query = from person in persons
let region = point.Buffer(radius)
where person.Location.Intersects(region)
select person;
我想使用Filter可能性(因为如果准确性不是您主要关心的问题,那么这可以加快您的查询速度,如下所示:http://www.pauldmendoza.com/post/SQL-Server-Filter-vs-STInterects.aspx http://www.pauldmendoza.com/post/SQL-Server-Filter-vs-STInterects.aspx)
但是,我似乎找不到如何在 EF5 中执行此操作。这可能吗?如果是的话:怎么办?
我正在使用 SQL Server 2008 R2。
问这个问题有点太早了。我找到了这个:http://msdn.microsoft.com/en-us/library/hh673622(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/hh673622(v=vs.110).aspx
可以这样使用:
var point = DbGeography.FromText(string.Format("POINT({1} {0})", latitude, longitude), 4326);
var query = from person in persons
let region = point.Buffer(radius)
where SqlSpatialFunctions.Filter(person.Location, region) == true
select person;
这转化为我想要的查询。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)