使用MySQL时在NHibernate中使用Guid as Id列会导致格式异常 [英] Using Guid as Id column in NHibernate causes format exception when using MySQL

查看:125
本文介绍了使用MySQL时在NHibernate中使用Guid as Id列会导致格式异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

有解决方案吗?现在,我仅使用普通的ol'int,但是以后的项目很高兴知道! :)

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! :)

推荐答案

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).

因为nhibernate中的当前MySQL方言没有更新以反映此更改,所以(实际上问题已准备好) 您需要手动转换这些 休眠后将字段转换为BINARY(16) 生成模式.

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.

这篇关于使用MySQL时在NHibernate中使用Guid as Id列会导致格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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