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

发布于 2024-09-10 08:26:22 字数 1000 浏览 2 评论 0原文

SQL Server 2008 R2 Express。 NHibernate 2.1.2.4。

我得到如下 SQL:

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

...即使其中有具有该 ID 的客户,它也会返回 0 条记录。

SQL Server 列数据类型是 UNIQUEIDENTIFIER。

配置如下:

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

类的 配置如下

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

在各种 tuts 的帮助下,我第一次通过此方法。我已经把所有事情都经历过好几次了,但没有任何快乐。任何想法这里有什么问题/遗漏吗?蒂亚!

Sql Server 2008 R2 Express. NHibernate 2.1.2.4.

I get SQL like:

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.

The SQL Server column datatype is UNIQUEIDENTIFIER.

<session-factory> configured as follows:

<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 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. I've been over everything several times but no joy. Any ideas what is wrong/missing here? TYIA!

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-09-17 08:26:22

似乎是正确的。根据 this "我们必须记住,Guid 不是字符串,即使我们认为 Guid 是一个 16 字节的数据结构。 ”。所以我不确定为什么你没有得到你期望的结果,但我认为生成的 SQL 没有引号是正确的。

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

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