Tuesday, April 19, 2016

SQLITE NHibernate DateTime2

While working on a project I was using a MsSQL 2012 database for my persistence layer but wanted to use a SQLITE in memory database for my unit/integration testing.  As part of my mapping setup I used an NHibernate Version column which used DateTime2:

NHibernate Mapping Code:

Unforntuently SQLITE doesn't support DateTime2. After searching around and not finding a good solution, I ended up extending SQLiteDialect class to map it to TEXT per the following link:   http://stackoverflow.com/a/16597386/2544235

SQLiteDialect Code:

1 comment:

  1. Thankyou!
    I have not delved into exactly how an why it works but in my case it was enough to:
    protected override void RegisterColumnTypes()
    {
    base.RegisterColumnTypes();
    RegisterColumnType(DbType.DateTime2, "DateTime2");
    }

    protected override void RegisterKeywords()
    {
    base.RegisterKeywords();
    RegisterKeyword("DateTime2");
    }

    I am only (diminishing) using SQLite for automatic testing and I am not sure I check my DateTime2s in my tests. But as long as tests show green I am good to go? Right! Right? Hello? Anybody still listening?

    ReplyDelete

Phoenix

I am resurrecting this tech blog for notes related to Azure Logic Apps with SAP.