如何阻止 NHibernate(通过 ActiveRecord)添加 this_.公式中的表名称

发布于 2024-09-24 00:57:42 字数 894 浏览 2 评论 0原文

我正在使用 Castle ActiveRecord,它在下面使用 NHibernate,并且我向我的实体之一添加了一个具有如下公式的属性:

[Property(Formula = "CAST((select count(*) from [User] as u where u.Email = FriendEmail) as bit)")]
public bool FriendRegistered { get; set; }

问题是现在对该实体的任何查询都会失败,因为 NHibernate 添加了 this_. 在公式中的 User 之前。这会产生以下 SQL:

CAST((select count(*) from this_.[User] as u where u.Email = this_.FriendEmail) as bit) as formula0_7_

我尝试使用不同的表名只是为了测试,效果很好,所以我猜它只会影响共享保留字的表,例如“User”。

我尝试使用反引号来转义它,还尝试删除“from”和“[User]”之间的空格,并尝试添加架构(dbo.),但都没有成功。

这听起来像是 NHibernate 中的一个错误,我发现这个错误报告类似: https://nhibernate .jira.com/browse/NH-1617

我想我的问题是:是否有解决方法或某个地方的设置,甚至有一种我不知道的处理方法?

我们使用 NH 2.1.2 和 MsSql2008Dialect 方言。

预先感谢

安迪

I'm using Castle ActiveRecord which uses NHibernate underneath and I've added a property with a formula as follows to one of my entities:

[Property(Formula = "CAST((select count(*) from [User] as u where u.Email = FriendEmail) as bit)")]
public bool FriendRegistered { get; set; }

The problem is that now any query for this entity fails because NHibernate adds this_. before User in the formula. This results in the following SQL:

CAST((select count(*) from this_.[User] as u where u.Email = this_.FriendEmail) as bit) as formula0_7_

I tried using a different table name just for testing and that worked fine so I guess it only affects tables that share a reserved word, such as "User".

I've tried using backticks to escape it, also tried removing the space between "from" and "[User]", and tried adding the schema (dbo.) all without success.

This sounds like a bug in NHibernate and I found this bug report which is similar: https://nhibernate.jira.com/browse/NH-1617

I guess my question is: Is there a workaround to this or a setting somewhere or even a way to handle this that I don't know about?

We're using NH 2.1.2 and the MsSql2008Dialect Dialect.

Thanks in advance

Andy

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

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

发布评论

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

评论(2

慕巷 2024-10-01 00:57:42

在 JIRA 问题的末尾,Fabio 在方言中提到了 RegisterKeyword("int"),因此我也尝试添加 RegisterKeyword("bit")

At the end of that JIRA issue, Fabio mentions a RegisterKeyword("int") in the dialect, so I'd try adding RegisterKeyword("bit") as well.

单身情人 2024-10-01 00:57:42

作为解决此问题的方法,我最终创建了一个名为 AllUsers 的视图,它只是执行了 select * from [User] 操作,然后将我的公式更新为您 AllUsers代码>而不是<代码>[用户]。

我知道这是一个小技巧,但这可能会帮助其他快速完成某些工作的人。

As a workaround for this I ended up creating a View called AllUsers which just did a select * from [User] and then updated my formula to you AllUsers instead of [User].

A bit of a hack I know, but this might help others that did something working quickly.

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