I have this query (Simple example, not the real one, I need to use the INTERSECT
):
SELECT Id,Geo FROM Locations WHERE Id=1
INTERSECT
SELECT Id,Geo FROM Locations WHERE Id>10
The column Geo is geometry type, and when I execute this query I get this error:
The data type geometry cannot be used as an operand to the UNION, INTERSECT or EXCEPT operators because it is not comparable.
However if I cast the property as nvarchar
, it works:
SELECT Id, CAST(Geo AS NVARCHAR(MAX)) as Geo
FROM Locations
WHERE Id = 1
INTERSECT
SELECT Id, CAST(Geo AS NVARCHAR(MAX)) as Geo
FROM Locations
WHERE Id > 10
Any ideas of how to do that cast with Linq IQueryable
??
var query1= _context.Set<Location>().Where(x => x.Id = 1);
var query2= _context.Set<Location>().Where(x => x.Id > 10);
var result= query1.Intersect(query2).ToList();
I have something like that, but I don't now how to do the cast of the property Geo. When I do the .ToList()
I get the same SqlError
:
The data type geometry cannot be used as an operand to the UNION, INTERSECT or EXCEPT operators because it is not comparable.
I'm using C# with Core 3.1