简体   繁体   English

NHibernate是否应为GUID参数生成不带引号的SQL?

[英]Should NHibernate generate SQL for GUID parameter without quotes?

Sql Server 2008 R2 Express. SQL Server 2008 R2 Express。 NHibernate 2.1.2.4. NHibernate 2.1.2.4。

I get SQL like: 我得到像这样的SQL:

SELECT customer0_.Id as Id1_0_ 
FROM customers customer0_ 
WHERE customer0_.Id=@p0;
@p0 = 11111111-1111-1111-1111-111111111111

...which returns 0 records even though there is Customer in there with that Id. ...即使其中存在带有该ID的客户,也将返回0条记录。

The SQL Server column datatype is UNIQUEIDENTIFIER. SQL Server列的数据类型为UNIQUEIDENTIFIER。

<session-factory> configured as follows: <session-factory>配置如下:

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>

Class's <id> configured as follows 类的<id>配置如下

<id name="_id" column="Id" type="Guid" access="field" unsaved-value="00000000-0000-0000-0000-000000000000" >
  <generator class="guid.comb" />
</id>

Forging my way through this for the first time, w/ the help of various tuts. 借助各种tut,我第一次在此过程中迈出了第一步。 I've been over everything several times but no joy. 我已经经历过好几次了,但是没有喜悦。 Any ideas what is wrong/missing here? 任何想法哪里错了/这里没有? TYIA! TYIA!

This seems correct. 似乎是正确的。 According to this "we must remember that a Guid is not a string even thought that's how we see them. A Guid is a 16-byte data structure." 根据这种说法,“我们必须记住,GUID甚至不是字符串,甚至认为这就是我们看到的字符串。GUID是一个16字节的数据结构。” So I'm not sure why you are not getting back the results you expect, but I think the generated SQL is correct in not having the quotes. 因此,我不确定您为什么不找回期望的结果,但是我认为生成的SQL在没有引号的情况下是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM