将't''f'转换为布尔值时,流畅的nhibernate错误"字符串未被识别为有效的布尔值."

Emm*_*uel 6 c# nhibernate fluent-nhibernate

使用布尔列从数据库获取记录时遇到问题.我无法改变数据库结构.
数据库类型是Character(1)(PostgreSQL),其中't'表示true,'f'表示false.我使用过PostgreSQLDialect.

我试过把它放在hibernate配置中

 <property name="query.substitutions">1 't',0 'f'</property>
Run Code Online (Sandbox Code Playgroud)

我试图用方言覆盖

 public override string ToBooleanValueString(bool value)
        {
            return value ? "t" : "f";
        }
Run Code Online (Sandbox Code Playgroud)

映射是:

Map(x => x.IsTemplate).Column("template_p");
Run Code Online (Sandbox Code Playgroud)

仍然没有工作,任何帮助?

Col*_*e W 6

您可能需要在此处创建自己的用户类型.以下是创建自己的示例:

http://lostechies.com/rayhouston/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype/

您的映射将变为如下所示:

Map(x => x.IsTemplate).Column("template_p").CustomType<MyCustomType>();
Run Code Online (Sandbox Code Playgroud)

编辑:

您也可以通过对查询 - 替换执行某些操作来使用标准的YesNo类型.我没有测试过这个,但可能是这样的:

<property name="query.substitutions">yes 't', no 'f'</property>
Run Code Online (Sandbox Code Playgroud)

您的映射看起来与我上面说的几乎相同,除非您使用YesNo类型.