Docs in https://docs.microsoft.com/en-us/ef/core/modeling/spatial say:
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
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.
Most helpful comment
This is fixed in 3.0-preview2 already.
Generated SQL:
The issue happens because old query pipeline did not parameterize
new Pointin query.To work-around this issue, you can define variable of
Pointoutside of linq query and refer to that variable rather than usingnew Pointinside the query.