使用 MySQL 时,在 NHibernate 中使用 Guid 作为 Id 列会导致格式异常
当我定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MySql 连接器文档指出,从 .NET 连接器版本 5.2 开始,它们将 GUID 视为 BINARY(16) 而不是 VARCHAR(40)。
MySql Connector documentation states that from version 5.2 of .NET connector they treat GUID's as BINARY(16) not VARCHAR(40).
对此的另一个更新是最新的连接器使用 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).