如何阻止 NHibernate(通过 ActiveRecord)添加 this_.公式中的表名称
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 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 addingRegisterKeyword("bit")
as well.作为解决此问题的方法,我最终创建了一个名为
AllUsers
的视图,它只是执行了select * from [User]
操作,然后将我的公式更新为您AllUsers
代码>而不是<代码>[用户]。我知道这是一个小技巧,但这可能会帮助其他快速完成某些工作的人。
As a workaround for this I ended up creating a View called
AllUsers
which just did aselect * from [User]
and then updated my formula to youAllUsers
instead of[User]
.A bit of a hack I know, but this might help others that did something working quickly.