I'm using .NET 4.5 and EF 6.0 (also tried with 6.1.3). I have Location geography column in an Entities table (System.Data.Entity.Spatial.DbGeography).
using System.Data.Spatial; //also tried Entity one
public class Entity
{
public DbGeography Location {get;set;}
}
In LINQ I'm trying to select all entities which are inside a specified area.
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();
And this query returns me an error:
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.
In case this is true:
http://referencesource.microsoft.com/#System.Data.Entity/System/Data/Objects/SqlClient/SqlSpatialFunctions.cs
How did this work in examples over the web?
UPD. The same problem using 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();