开发者

Scalar-Valued Function in NHibernate

I have the following scalar function in MS SQL 2005:

CREATE FUNCTION [dbo].[Distance] ( @lat1 float,  @long1 float,@lat2 float, @l开发者_如何学Cong2 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?


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

  • http://nhforge.org/blogs/nhibernate/archive/2009/03/13/registering-freetext-or-contains-functions-into-a-nhibernate-dialect.aspx
  • http://www.gg3721.com/list/9/23031.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜