将sql server spatial和NHibernate与CreateSqlQuery相结合

时间:2012-11-03 22:16:34

标签: sql-server nhibernate spatial geography

我没有在sql server 2008中映射地理表,我想使用nhibernate在c#中使用多边形实例进行查询。
在开始时我试图直接使用sql server spatial但是遇到了这个问题: Using SQL Server 2008 Geography types with nHibernate's CreateSQLQuery

我的第二次尝试是这样的:

session.CreateSQLQuery("select [shape] from [table] where (:codeShape).STIntersects([shape]) = 1").SetParameter("codeShape", codeShape, NHibernateUtil.Custom(typeof(MsSql2008GeographyType)));

但是这个尝试也会引发异常:

Could not execute query [select [shape] from [table] where (?).STIntersects([shape]) = 1")] Name:codeShape - Value:POLYGON((30 40, ...))

,内部例外是:

The specified input does not represent a valid geography instance.

尽管codeShape.IsValid仍然返回true。

当我直接在sql server中运行此查询时,我得到了预期的结果。

任何想法或解决方案?

感谢。

1 个答案:

答案 0 :(得分:0)

问题解决了。我不得不反转多边形的点。