sqlite with nhibernate - a guide to getting it working

Wednesday, May 27th, 2009

I 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!

New release of the ajax control toolkit

Thursday, May 14th, 2009

http://weblogs.asp.net/bleroy/archive/2009/05/13/new-release-of-the-ajax-control-toolkit.aspx

NAct - a .NET port of Jbehave

Wednesday, May 13th, 2009

NAct is now on google code. Built by Tim Wilde from TechnoPhobia (my place of work).

Super duper:

http://code.google.com/p/nact

Quartz.NET - open source job scheduling system

Wednesday, May 13th, 2009

How have I missed this for so long!

http://quartznet.sourceforge.net/

Lucene.NET Did you mean? - easy how to…

Sunday, May 10th, 2009

This is actually very simple to do and you can get it done in about 20 mins! I did a bit of Googling and could not find much about it so I thought that I should share my findings.

First of all you need an additional assembly called SpellChecker.Net. This assembly is a part of lucene.net and can be found in the contrib directory. I checked it out from SVN here: https://svn.apache.org/repos/asf/incubator/lucene.net/trunk/C#/contrib/SpellChecker.Net

Just open the solution and then build it in release configuration. That’s it - you now have the SpellChecker dll you need.

Now all you have to do is add a reference to this in the project that you have lucene etc (you get what I am on about I am sure).

Ok so now for the fun bit - actually using it! This is simpler than you might expect. In my case I added it to my SearchEngine class. This may be the right or wrong thing to do but for now it felt right - I perform a search on the engine - why not ask it for the suggestions too?

Ok so here is the code:
private void createSuggestionList()
{
var spellChecker = new SpellChecker.Net.Search.Spell.SpellChecker(_searcher.Reader.Directory());
spellChecker.IndexDictionary(new LuceneDictionary(_searcher.Reader, "title"));
_suggestions = spellChecker.SuggestSimilar(_originalSearchTerm, 5);
}

Ok so let me explain:

  • Firstly we create an instance of the spell checker and pass in a directory. ‘_searcher’ is an instance of ‘IndexSearcher’ (you should be aware of one of these are if you are using Lucene)
  • Then we tell the spellChecker which index to read and which field to gather its spelling suggestions from
  • All we have to do now is grab an array of strings from a search term

I told you it was easy - enjoy….

The remote server returned an error: (417) Expectation Failed

Friday, May 1st, 2009

This is a really obscure error so I thought that I would share the solution.

This is caused by an additional header ‘HTTP header “Expect: 100-Continue”‘ being added to the request. The solution is to set the following:

System.Net.ServicePointManager.Expect100Continue = false;

Great - what a pile…

elmah Error Logging Modules and Handlers for ASP.NET

Friday, May 1st, 2009

http://code.google.com/p/elmah/

C# ?? null coalescing with Linq

Friday, May 1st, 2009

http://weblogs.asp.net/scottgu/archive/2007/09/20/the-new-c-null-coalescing-operator-and-using-it-with-linq.aspx