Efcore: LINQ not translated when filtering with NTS (NetTopologySuite)

Created on 26 Feb 2019  路  1Comment  路  Source: dotnet/efcore

Docs in https://docs.microsoft.com/en-us/ef/core/modeling/spatial say:

Querying Data

In LINQ, the NTS methods and properties available as database functions will be translated to SQL. For example, the Distance and Contains methods are translated in the following queries. The table at the end of this article shows which members are supported by various EF Core providers.

But using:

........Where(c => c.Polygon.Contains(new Point(longitude, latitude) { SRID = 4326 }))........

(Polygon is of type IGeometry)

I get:

The LINQ expression 'where [c].Polygon.Contains(new Point(__longitude_0, __latitude_1) {SRID = 4326})' could not be translated and will be evaluated locally.

Using: .NET Core 2.2.2

closed-fixed customer-reported type-bug

Most helpful comment

This is fixed in 3.0-preview2 already.
Generated SQL:

      SELECT [e].[Id], [e].[Point], [e].[Polygon]
      FROM [Blogs] AS [e]
      WHERE [e].[Polygon].STContains(@__p_0) = 1

The issue happens because old query pipeline did not parameterize new Point in query.
To work-around this issue, you can define variable of Point outside of linq query and refer to that variable rather than using new Point inside the query.

>All comments

This is fixed in 3.0-preview2 already.
Generated SQL:

      SELECT [e].[Id], [e].[Point], [e].[Polygon]
      FROM [Blogs] AS [e]
      WHERE [e].[Polygon].STContains(@__p_0) = 1

The issue happens because old query pipeline did not parameterize new Point in query.
To work-around this issue, you can define variable of Point outside of linq query and refer to that variable rather than using new Point inside the query.

Was this page helpful?
0 / 5 - 0 ratings