我正在使用.NET 4.5和EF 6.0(也尝试过6.1.3)。
我在实体表中有一个位置地理列(System.Data.Entity.Spatial.DbGeography)。
如果这是真的:
using System.Data.Spatial; //also tried Entity one
public class Entity
{
public DbGeography Location {get;set;}
}
在LINQ中,我正在尝试选择所有位于指定区域内的实体。
var center = DbGeography.FromText(string.Format("POINT({0} {1})", latitude, longitude), 4326);
var region = center.Buffer(radius);
var result = db.Entities.Where(x => SqlSpatialFunctions.Filter(x.Location, region) == true).ToArray();
这个查询返回了一个错误:
An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
Additional information: The specified type member 'Location' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
如果这是真的:
http://referencesource.microsoft.com/#System.Data.Entity/System/Data/Objects/SqlClient/SqlSpatialFunctions.cs
这在网上的示例中是如何工作的?
更新。使用Intersects()时出现相同的问题。
var center = DbGeography.FromText(string.Format("POINT({0} {1})", latitude, longitude), 4326);
var region = center.Buffer(radius);
var result = db.Entities.Where(x => x.Location.Intersects(region) == true).ToArray();