【发布时间】:2015-09-06 20:22:57
【问题描述】:
我正在使用 .NET 4.5 和 EF 6.0(也尝试使用 6.1.3)。 我在实体表 (System.Data.Entity.Spatial.DbGeography) 中有 Location geography 列。
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。使用 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();
【问题讨论】:
标签: c# entity-framework-6 geospatial spatial-query