Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:50:42+00:00 2026-06-15T06:50:42+00:00

I have the following code: private static ISessionFactory CreateSessionFactory() { ISessionFactory factory = null;

  • 0

I have the following code:

private static ISessionFactory CreateSessionFactory()
{
    ISessionFactory factory = null;

    var cfg = new Configuration();

    // Do this to map bool true/false to DB2 char('0') or char('1')
    var props = new Dictionary<string, string>(); 
    props.Add("query.substitutions","true=1;false=0");
    cfg.AddProperties(props);

    cfg.DataBaseIntegration(x =>
    {
        x.ConnectionString = CONNECTION_STRING;
        x.Dialect<DB2400Dialect>();
        x.Driver<DB2400Driver>();
    });

    factory = Fluently.Configure(cfg)
        .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
        .BuildSessionFactory();

    return factory;
}

In my POCO, I have the property:

public virtual bool QCCount { get; set; }

In my mapping, I have

Map(x => x.QCCount, "QCNT36");

In DB2, there are no bit fields, only char(1) with ‘0’ or ‘1’.

As I understand it, the props.Add(“query.substitutions”,”true=1;false=0″); should map these 0’s and 1’s to boolean POCO objects, however, it doesn’t seem to be working.

Do I need to add something to the mapping of the field to tell it to use this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:50:44+00:00Added an answer on June 15, 2026 at 6:50 am

    I found a solution that seems to work.

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

    I changed the ‘Y’, ‘N’ to ‘0’ and ‘1’, then map the column and it’s processing fine.

    Code:

    public class CharBoolType : IUserType
    {
        public bool IsMutable
        {
            get { return false; }
        }
    
        public Type ReturnedType
        {
            get { return typeof(CharBooleanType); }
        }
    
        public SqlType[] SqlTypes
        {
            get { return new[] { NHibernateUtil.String.SqlType }; }
        }
    
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            var obj = NHibernateUtil.String.NullSafeGet(rs, names[0]);
    
            if (obj == null) return null;
    
            var trueFalse = (string)obj;
    
            if (trueFalse != "1" && trueFalse != "0")
                throw new Exception(string.Format("Expected data to be '0' or '1' but was '{0}'.", trueFalse));
    
            return trueFalse == "1";
        }
    
        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            if (value == null)
            {
                ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
            }
            else
            {
                ((IDataParameter)cmd.Parameters[index]).Value = (bool)value ? "1" : "0";
            }
        }
    
        public object DeepCopy(object value)
        {
            return value;
        }
    
        public object Replace(object original, object target, object owner)
        {
            return original;
        }
    
        public object Assemble(object cached, object owner)
        {
            return cached;
        }
    
        public object Disassemble(object value)
        {
            return value;
        }
    
        public new bool Equals(object x, object y)
        {
            if (ReferenceEquals(x, y)) return true;
    
            if (x == null || y == null) return false;
    
            return x.Equals(y);
        }
    
        public int GetHashCode(object x)
        {
            return x == null ? typeof(bool).GetHashCode() + 473 : x.GetHashCode();
        }
    }
    

    Mapping:

    Map(x => x.QCCount, "QCNT36").CustomType<CharBoolType>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: private void _DoValidate(object sender, DoWorkEventArgs e) { this.BeginInvoke(new MethodInvoker(()
I have the following code private Map<KEY, Object> values = new HashMap<KEY, Object>(); public
I have the following code: private static LogLevel? _logLevel = null; public static LogLevel
I have the following code: private static object _dbLock = new object(); public static
I have the following code: private static HashSet<SoloUser> soloUsers = new HashSet<SoloUser>(); public void
I have following code private static ObservableCollection<myColor> myItems = new ObservableCollection<myColor>(); myItems.Add(new myColor(red)); When
I have the following code: private static final Set<String> allowedParameters; static { Set<String> tmpSet
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have the following code: public class Test extends JFrame implements ActionListener{ private static
I currently have code that does the following: private final static ExecutorService pool =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.