NHibernate中的标量值函数 [英] Scalar-Valued Function in NHibernate

查看:87
本文介绍了NHibernate中的标量值函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS SQL 2005中具有以下标量函数:

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

我需要能够从我的NHibernate查询中调用此函数.我阅读了这篇文章,但是我陷入了一些我不了解的细节.

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.

如果您在NHibernate中使用了标量函数,能否给我一个示例,说明您的HBM文件如何查找类似这样的函数?

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:

这篇关于NHibernate中的标量值函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆