LINQ to Entity does not support DbGeography conditions

c# entity-framework-6 geospatial spatial-query

Question

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();
1
4
9/7/2015 7:04:25 PM

Popular Answer

In my case my Linq query would not allow me to use:

x.Intersects(region) == true

I had to change this to

x.Intersects(region).IsTrue
0
10/6/2017 1:30:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow