NHibernate with csharp-sqlite embedded C# database

Following my [NH-2120] post on JIRA, I decided to make another post here, just in case I need it in the future. Maybe for instance my driver does not get accepted for whatever reason.

So what I have done is created a driver for the managed embedded SQLite C#/.NET re-implementation database called C#SQLite (see csharp-sqlite project) and have tested this with the latest versions of csharpsqlite and NHibernate (2.1.2.GA using the SQLiteDialect).

This database re-implementation is really bringing together a number of very attractive things, such as fully managed code, .NET 2.0 requirement only, multi-platform support via Mono, OK performance, embeddable, etc, etc. So download a copy of the latest database and ADO.NET provider first.

Then you need the NHibernate sources. Open them up and create a new driver file in NHibernate.Driver called CsharpSqlite.cs

Once the driver file (link 1, link 2) is included/pasted in the project, I had to recompile NHibernate and NHibernate.Bytecode.LinFu (you may want to recompile the bytecode provider of your own choice e.g. Castle). I'm using it with 2.1.2.GA currently and C#-SQLite version 3.6.22 (latest at the moment) without problems. EDIT: The very latest version (3.6.23) is broken, I'm investigating this and will submit a patch. In the mean time, use my 3.6.22 binary.

For your own project, the usual NHibernate libraries need to be referenced, consult NHibernate documentation for this. But make sure you include the assemblies "Community.CsharpSqlite" (SQLite managed implementation) and "Community.CsharpSqlite.SQLiteClient" (the ADO.NET provider), both available from noah.hart's csharp-sqlite webpage (EDIT: use my binary above!).

Some of these libraries (e.g. CSharp SQLite itself as well as the Client) appear to target .NET 3.5, but setting them all to .NET 2.0 caused no compilation errors and they worked just fine for me.

Enjoy!

4 comments:

  1. Hey. I'm having some trouble with this using a parameterized insert statement. Do you know if there are any issues with that? I'm using the same code as I had used with System.Data.SQLite.

    ReplyDelete
  2. Nevermind. I updated line 249 of SqliteCommand.cs to be: if (!String.IsNullOrEmpty(name)) instead of if (name != null)

    ReplyDelete
  3. Here is a database compatible with .NET, Silverlight, Windows Phone, Mono, Monodroid, and Monotouch:
    http://www.kellermansoftware.com/p-43-ninja-net-database-pro.aspx

    ReplyDelete
  4. nic post
    http://mkniit.blogspot.in

    ReplyDelete