sqlite with nhibernate - a guide to getting it working
Wednesday, May 27th, 2009I am currently working on a new project and I am going full on TDD and BDD (where appropriate). As I have been in a variety of different environments I want to be able to check out the project, run the tests and write some code. My integration tests rely on a database (currently proving that my nhibernate mappings are correct) and I did not want there to be a dependency on having a database running so I wanted to use sqlite.
Here is what I did:
Download sqlite:
http://sourceforge.net/projects/sqlite-dotnet2
Get an sqlite GUI admin tool:
http://sqliteadmin.orbmu2k.de/
Create a database to connect to.
Change you nhibernate config file:
<?xml version="1.0" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property> <property name="dialect"> NHibernate.Dialect.SQLiteDialect </property> <property name="connection.driver_class"> NHibernate.Driver.SQLite20Driver </property> <property name="connection.connection_string"> Data Source=directory-in-your-test-assembly\your-database.s3db </property> <property name="query.substitutions">true=1;false=0</property> <mapping assembly="YourAssembly" /> </session-factory> </hibernate-configuration>
Notice that I have used the SQLite20Driver instead of SQLiteDriver (it won’t work otherwise!)
Don’t forget to make sure that your db is copied to your output directory.
I will expand upon this post tomorrow when I have more time!
