我正在使用.NET 4.5和EF 6.0(也试过6.1.3)。 我有位置地理列在实体表(System.Data.Entity.Spatial.DbGeography)。LINQ to Entity不支持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
如何做这项工作在网上的例子吗?
UPD。同样使用的问题相交()
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();
更新的帖子。 Intersects()引发相同的异常。 – deeptowncitizen
@deeownowncitizen - 多奇怪!你正在使用EF6?你如何绘制表格? –
是的,那就是EF6。我有一张Lng,Lat字段的桌子。我添加了地理类型的位置。并将这个新列映射到Entity DbGeography。 btw SQL请求运作良好 – deeptowncitizen