Bas*_*aad 3 c# linq sql-server entity-framework spatial
使用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;
Run Code Online (Sandbox Code Playgroud)
我想使用过滤器的可能性(因为这可以加快您的查询,如果准确性不是您主要关注的问题,请参阅: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 = vs1010).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;
Run Code Online (Sandbox Code Playgroud)
这转换为我想要的查询.
| 归档时间: |
|
| 查看次数: |
4410 次 |
| 最近记录: |