为 POINT postgresql 数据类型(或非原始类似 nhibernate 类型的任何列)实现新的 NHibernate 类型

发布于 2024-09-25 19:32:38 字数 859 浏览 2 评论 0原文

我对 NHibernate 和 postgresql POINT 数据类型有疑问(尽管我相信对于所有尝试映射 NHibernate SqlTypes 未涵盖的 SQL 类型的人来说这是一个常见问题)。

我的 Data.Point 类有两个公共浮点数:x 坐标和 y 坐标。

我的第一次尝试是尝试实现 IUserType 接口,但我很快发现问题出现得更早,在映射阶段:

用户代码未处理 MappingException:
无法确定类型:Data.PointUserType,Data.Point,列:NHibernate.Mapping.Column(坐标)

我对 NHibernate 很陌生,但在我看来,我只能创建一个新类型,如果列在数据库是已知类型(float、int、varchar 和所有“经典”类型之一,但不是我需要的几何类型)。

通过映射到坐标[0]和坐标[1],我成功地将我的点映射到两个不同的属性。但这仅对 SELECT 和 UPDATE 查询有用,对于 INSERT postgresql 会抱怨“坐标”不可为空。

另外,我找不到 NHibernate Spatial 扩展的实际版本,而且我更愿意控制我的 POINT 类型,因为我很少使用这种类型,因此我宁愿不加载整个 NHibernate Spatial程序集(假设它们正在积极开发,否则我无论如何都会远离它们)。

我最后的想法是,我需要搞乱 NHibernate 的 SQL 生成(因为插入 SQL 的某些部分将是 '(a, b)'::point,非常具体的东西),也许这就是有点太麻烦了(也许不是,我愿意检查一下)。

我对 NHibernate 还很陌生,但我越来越绝望了。 谁能指出我的地方吗?

I have a problem with NHibernate and the postgresql POINT data type (although I believe this is a common problem for all of those trying to map a SQL TYPE that is not covered by NHibernate SqlTypes).

My Data.Point class has two public floats: xcoordinate and ycoordinate.

My first attempt was trying to implement the IUserType interface, but I soon found out that the problem comes earlier, during the mapping phase:

MappingException was unhandled by user code:
Could not determine type for: Data.PointUserType,Data.Point, for columns: NHibernate.Mapping.Column(coordinates)

I'm very new to NHibernate, but it seems to me that I can only create a new type if the column in the database is of a known type (one of float, int, varchar and all "classic" types, but not the geometric ones I need).

I had managed to map my POINT to two different properties, by mapping to coordinates[0] and coordinates[1]. But this is only useful for SELECT and UPDATE queries, as for INSERT postgresql will complain that "coordinates" is not nullable.

Also, I can't find an actual version of NHibernate Spatial extensions, and I'd much rather have control of my POINT type, since I'll be using this type very seldom, and thus I would rather not load the entire NHibernate Spatial assemblies (supposing they are actively developed, otherwise I'll keep away from them anyways).

My final thoughts are that I would need to mess with NHibernate's SQL Generation (since some part of the insertion SQL would be '(a, b)'::point, something very specific), and maybe that's a little too troublesome (maybe not, I'd be willing to check it out).

I'm fairly new to NHibernate, but I'm getting desperate.
Can anyone point me somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深缘浅 2024-10-02 19:32:38

我最近让 nHibernate 与 SQL Server 2008 一起工作。要了解如何查看这个问题: NHibernate.Spatial 和 Sql 2008 地理类型 - 如何配置

如果您包含映射文件,会更容易提供帮助。我想知道您是否正确注册了您的 IUserType?它应该看起来像这样

<class name="WhereAmI">
    <property name="Point">
        <type name="MyProject.MyPointUserType, MyProject">
        </type>
    </property>
</class>

另请考虑查看以下适用于 MS SQL Servier 2008 的 IUserType 实现:NHibernate.Spatial.Type.GeometryType

I recently got nHibernate working with SQL Server 2008. To see how see this question: NHibernate.Spatial and Sql 2008 Geography type - How to configure

It would be easier to help if you included you mapping file. I'm wondering if you have correctly registered your IUserType? It should look something like this

<class name="WhereAmI">
    <property name="Point">
        <type name="MyProject.MyPointUserType, MyProject">
        </type>
    </property>
</class>

Also consider taking a look at the following IUserType implementation which works for MS SQL Servier 2008: NHibernate.Spatial.Type.GeometryType

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文