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?
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:
Mapping: