Strangely I cannot use this function mapping:
Add(new FunctionMapping(typeof(GeoLocationFunctions), "STEquals", 2, "{0}.STEquals({1})"));
When calling this:
LinqMetaData lmd = new LinqMetaData(null, new GeoFunctionMappings());
SqlGeography geography = SpatialHelper.CreateGeogPoint(-34.0493, 18.3292);
var locations = from location in lmd.Location
where GeoFunctions.GetDistance(geography , location.GeoLocation ) > 0
&& location.TotalAccommodation > 0
&& location.LocationTypeId == 3
orderby GeoFunctions.GetDistance(geography, location.GeoLocation)
select
new
{
location.LocationId,
location.LocationName,
distance = GeoFunctions.GetDistance(geography, location.GeoLocation)
};
I get the following error:
Exception information:
Exception type: ORMQueryExecutionException
Exception message: An exception was caught during the execution of a retrieval query: Cannot call methods on nvarchar..
I have to use this:
Add(new FunctionMapping(typeof(GeoFunctions), "GetDistance", 2,
"GetDistanceSpatial({0}, {1})", "---", "dbo"));
which simply invokes the following user defined function
---calculates the distance between two places, typically a place and a seller product
ALTER FUNCTION [dbo].[GetDistanceSpatial]
(
@GeoLocation1 geography,
@GeoLocation2 geography
)
RETURNS float
AS
BEGIN
return @GeoLocation1.STDistance(@GeoLocation2);
END
Am I missing something , or are there other library changes I might need?
Thanks