使用 MySQL 时,在 NHibernate 中使用 Guid 作为 Id 列会导致格式异常

发布于 2024-07-24 19:08:39 字数 154 浏览 3 评论 0原文

当我定义 NHibernate 实体/映射以使用 Guid 作为标识列时,我收到一个异常。 Guid 列生成为 varchar(40),但内容似乎是二进制的。

有针对这个的解决方法吗? 现在我只使用普通的 ol' int,但如果知道对于未来的项目会很高兴! :)

When I define the NHibernate entity/mapping to use Guid as identity column I receive an exception. The Guid column is generated as a varchar(40), but the content seem to be binary.

Is there a solution to this? For now I'm just using plain ol' int, but it would be nice to know for future projects! :)

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

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

发布评论

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

评论(2

儭儭莪哋寶赑 2024-07-31 19:08:39

MySql 连接器文档指出,从 .NET 连接器版本 5.2 开始,它们将 GUID 视为 BINARY(16) 而不是 VARCHAR(40)

由于 nhibernate 中当前的 MySQL 方言未更新以反映此更改(实际上 已准备好问题
你需要手动转换这些
nhibernate 后将字段转换为 BINARY(16)
生成架构。

MySql Connector documentation states that from version 5.2 of .NET connector they treat GUID's as BINARY(16) not VARCHAR(40).

Since current MySQL dialect in nhibernate doesn't updated to reflect this change (actually an issue is prepared)
you need to manually convert these
fields to BINARY(16) after nhibernate
generate the schema.

两个我 2024-07-31 19:08:39

对此的另一个更新是最新的连接器使用 Char(36)

该选项是在 Connector/NET 6.1.1 中引入的。 GUID 类型的后端表示形式已从 BINARY(16) 更改为 CHAR(36)。 这样做是为了允许开发人员使用服务器函数 UUID() 填充 GUID 表 - UUID() 生成 36 个字符的字符串。 旧应用程序的开发人员可以将“Old Guids=true”添加到连接字符串中,以便使用数据类型 BINARY(16) 的 GUID。

Another update to this is that the latest connectors use Char(36)

This option was introduced in Connector/NET 6.1.1. The backend representation of a GUID type was changed from BINARY(16) to CHAR(36). This was done to allow developers to use the server function UUID() to populate a GUID table - UUID() generates a 36-character string. Developers of older applications can add 'Old Guids=true' to the connection string in order to use a GUID of data type BINARY(16).

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