LINQ to Entity does not support DbGeography conditions

c# entity-framework-6 geospatial spatial-query

Question

I'm running EF 6.0 and.NET 4.5. (also tried with 6.1.3). In an Entities table, there is a Location geography column for me (System.Data.Entity.Spatial.DbGeography).

using System.Data.Spatial; //also tried Entity one

public class Entity
{
    public DbGeography Location {get;set;}
}

I'm attempting to pick all entities that are included within a given area using 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();

And this query gives me a failure:

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.

If this is accurate:

http://referencesource.microsoft.com/#System.Data.Entity/System/Data/Objects/SqlClient/SqlSpatialFunctions.cs

How did this function in online examples?

UPDATE: Intersects presents the same issue ()

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

My Linq query would prevent me from using:

x.Intersects(region) == true

This had to be changed 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