转换“t”时出现流利的 nhibernate 错误; 'f' to boolean “字符串未被识别为有效的布尔值。”
我在使用布尔列从数据库获取记录时遇到问题。我无法更改数据库结构。
数据库类型是Character(1) (PostgreSQL),其中“t”表示 true,“f”表示 false。我用过 PostgreSQLDialect。
我试图将其放入休眠配置中,
<property name="query.substitutions">1 't',0 'f'</property>
我试图用方言覆盖
public override string ToBooleanValueString(bool value)
{
return value ? "t" : "f";
}
映射是:
Map(x => x.IsTemplate).Column("template_p");
仍然不起作用, 有什么帮助吗?
I've got a problem when getting a record from the database with a boolean column. I can't change the database structure.
The database type is Character(1) (PostgreSQL) where they used 't' for true and 'f' for false. I have used the PostgreSQLDialect.
I've tried to put this in the hibernate-configuration
<property name="query.substitutions">1 't',0 'f'</property>
I've tried to override in the dialect
public override string ToBooleanValueString(bool value)
{
return value ? "t" : "f";
}
The mapping is:
Map(x => x.IsTemplate).Column("template_p");
Still not working,
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能必须在此处创建自己的用户类型。以下是创建您自己的示例:
http://lostechies.com/rayhouston/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype/
然后你的映射将变成这样:
编辑:
您还可以通过对查询替换执行某些操作来使用标准 YesNo 类型。我还没有对此进行测试,但可能是这样的:
您的映射看起来与我上面所述的几乎相同,只是您将使用 YesNo 类型。
You may have to create your own user type here. Here is an example of creating your own:
http://lostechies.com/rayhouston/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype/
Your mapping would then become something like this:
Edit:
You might also be able to use the standard YesNo type by doing something with your query-substitiutions. I haven't tested this but maybe something like this:
Your mapping would look pretty much the same as I stated above except you would use the YesNo type.
事实上,Cole W,我制作了这个自定义类型,它的效果就像一个魅力
(源链接:https://lostechies.com/rayhouston/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype/)
Indeed Cole W, i made this customtype and it works like a charm
(source link: https://lostechies.com/rayhouston/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype/)
没有尝试过,但也许这可以工作:
Haven't tried, but maybe this could work:
我们使用带有布尔值的 postgres 8.3-8.4,没有任何问题。然而,当使用基于 ANTLR3 的 HQL 解析器时,它开始对布尔替换变得挑剔,因此我们使用以下覆盖创建了自己的方言:
但是,我们使用 NHibernate.Dialect.PostgreSQL82Dialect,而不是通用的。你运行的 postgres 版本是什么?
编辑:哦,抱歉,我没有注意到您有一个字符(1)列。也许这会有所帮助(带引号)?
We are using postgres 8.3-8.4 with boolean values without any problems. However, when using ANTLR3 based HQL parser it started to get picky about boolean substitution, so we made our own dialect with the following override:
However, we used NHibernate.Dialect.PostgreSQL82Dialect, not the generic one. What postgres version are you running?
EDIT: Oh, sorry, I didn't follow that you hade a character(1) column. maybe this would help instead (with the quotes)?