views:

132

answers:

1

I have the following scalar function in MS SQL 2005:

CREATE FUNCTION [dbo].[Distance] ( @lat1 float,  @long1 float,@lat2 float, @long2 float )
RETURNS float
AS
BEGIN
    RETURN (3958*3.1415926*sqrt((@lat2-@lat1)*(@lat2-@lat1) + cos(@lat2/57.29578)*cos(@lat1/57.29578)*(@long2-@long1)*(@long2-@long1))/180);
END

I need to be able to call this function from my NHibernate queries. I read over this article, but I got bogged down in some details that I didn't understand right away.

If you've used scalar functions with NHibernate, could you possibly give me an example of how your HBM file would look for a function like this?

A: 

This is not configurable in the mapping files but in the dialect. You need to create a custom dialect and register your function. Examples:

Mauricio Scheffer
Thanks. You're absolutely right.
Byron Sommardahl