Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fluent nhibernate error when converting 't' 'f' to boolean "String was not recognized as a valid Boolean."

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?

like image 983
Emmanuel Avatar asked May 03 '11 11:05

Emmanuel


1 Answers

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:

Map(x => x.IsTemplate).Column("template_p").CustomType<MyCustomType>();

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:

<property name="query.substitutions">yes 't', no 'f'</property>

Your mapping would look pretty much the same as I stated above except you would use the YesNo type.

like image 68
Cole W Avatar answered Oct 28 '22 08:10

Cole W