This is a mirror of official site: http://jasper-net.blogspot.com/

Sqlite-Csharp and NHibernate

| Wednesday, June 9, 2010
Taking a brief  interlude from my RavenDB series, I was doing some work on an internal project tonight with the build scripts and test-runner and I finally got bored of having to deal with un-managed SQLite dependencies with a project which other than that was platform agnostic.

The problem with having un-managed dependencies in a managed project is that Visual Studio quite frankly sucks at it, you can set up certain projects (in this case the tests) to be x86 only, and remove their Any CPU configuration – but as soon as you add a new project to the solution it decides to re-add the old configuration and potentially break things again.

This doesn't really rear any problems until you write a build script and things start falling over as your test runner tries to run as an x64 process and tries to load in the x86 dependency, or any number of combinations where this kind of thing can blow up. If it can happen, it will happen and it’s just something I’d rather not deal with.

So I had a look at Sqlite-Csharp, the code is atrocious as far as natively written C# libraries go (that’s not the point though, it’s a *port*), but it looks to be a superb direct-port of a C project (Sqlite) and passes most of the tests that it needs to in order for it to be viable for use in at least our in-memory tests.

Anyway, you can’t download binaries, so you have to build it – but no changes are required so just do it.

I’m not going to cover the process of setting up in-memory databases for testing with SQLite as that’s an easily Google-able topic, but there are a few differences between doing it with the unmanaged libraries and with the pure managed libraries.

This is what my FluentNHibernate configuration looks like:

  1:  Fluently.Configure()
  2:              .Database(
  3:                   SQLiteConfiguration.Standard.ConnectionString(
  4:                        x => x.Is(mConnectionString)).Driver<SqliteDriver>());

I’ve had to create a driver to make this work properly as there isn’t one provided as stock in NHibernate, the code for this is as simple as this:

Read more: Rob Ashton

Posted via email from jasper22's posterous

0 comments: