Question

I'm generating Entity SQL to provide dynamic query support in my application. I have however been unable to find how one is able to specify spatial conditions in Entity SQL using Entity Framework 5.

A query using Linq to Entities against a model with an entity containing a spatial field like:

var a = new Model1Container();
var b = from c in a.Entity1
        where c.Loc.Intersects(System.Data.Spatial.DbGeography.FromText("POINT (43 -73)"))
        select c;

generates the SQL that one would expect for SQL Server 2012, such as:

SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[Loc] AS [Loc]
FROM [dbo].[Entity1] AS [Extent1]
WHERE ([Extent1].[Loc].STIntersects(geography::Parse(N'POINT (43 -73)'))) = 1

How does one rewrite the above Linq to Entities query using ESQL? Or is this impossible?

Was it helpful?

Solution

We have a set of canonical functions that can be used in EntitySQL to operate with spatial types, which include instance construction from well-known text. For instance, this is valid EntitySQL for constructing a point:

GeometryFromText('POINT (43 -73)')

The full set of spatial canonical functions is declared in the SpatialEdmFunctions class, but this class is used for creating DbExpression trees programmatically, so the reference documentation available for this class is not in the most appropriate form for EntitySQL usage. I will follow up with our documentation team to see if there is a better resource available or if we need to add these to the EntitySQL documentation.

OTHER TIPS

var a = new YourDbContext();
var b = a.Entity1.Where(c=>c.Loc.Intersects(System.Data.Spatial.DbGeography.FromText("POINT (43 -73)"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top