Scalar-Valued Function in NHibernate

流过昼夜 提交于 2019-12-13 02:15:21

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/2481737/scalar-valued-function-in-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!