abeppler
abeppler

Reputation: 13

Fluent NHibernate mapping using a condition

I have a class with a boolean property, like this:

public bool HasPermission { get; set; }

but in our database, in this column we have information in varchar, and we have values like:

"yes","y","no","n","0","1"

How can I map this values to a bool property?

Upvotes: 0

Views: 766

Answers (1)

Javi bl
Javi bl

Reputation: 93

Sorry, should have written this as a comment but not enough rep; have you tried query substitutions?

Something like

    <property name="query.substitutions">
        true 1, false 0, true 'y', false 'n' 
    </property>

should work


Edit after comment: as keyess has pointed out, for fluent nhibernate, something like this

        var props = new Dictionary<string, string>();
        props.Add("query.substitutions","true=1;false=0")
        props.Add("query.substitutions","true=yes;false=no")
        props.Add(...)
        var sessionFactory = Fluently.Configure().BuildConfiguration().AddProperties(props);

should work (see this answer)

Also, another approach may be used based on IUserType

Upvotes: 2

Related Questions