From System.Data.Entity.SqlServer.SqlSpatialFunctions
class definition:
Contains function stubs that expose SqlServer methods in Linq to Entities.
I know that Linq to Entities is mentioned specifically, however I was wondering if some functionality can be replicated in my back end code.
I've got an account Model, with lazy loaded collection of Polygons. Each Polygon contains a DbGeography type property called Location.
I'm trying to get all Polygons that interesct certain point (which also has lazy loaded property Address, which has DbGeography type property called Location).
I can do it like this:
var matchedPolygons =
account.Polygons.Where(
x =>
point.Address.Location.Intersects(x.Polygon.Location)).ToList();
which works fine.
In order to try to improve the performance, I thought it would be a good idea to slightly reduce the Polygon data.
var matchedPolygons =
account.Polygons.Where(
x =>
point.Address.Location.Intersects(SqlSpatialFunctions.Reduce(x.Polygon.Location, 100))).ToList();
This however throws the following System.NotSupportedException exception:
This function can only be invoked from LINQ to Entities.
I know I can retrieve the polygons directly from my repository layer using the Reduce method above, but since I'm using lazy loading and have Polygons collection available to me already, I thought there might be a way of using SqlSpatialFunctions at this stage.