Showing posts with label NHibernate. Show all posts
Showing posts with label NHibernate. Show all posts

2009-09-23

Using NHibernate and SQLite on x64

If you are using a x64 OS, and have a reference to System.Data.SQLite and NHibernate throws exceptions like these:

  • NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
  • NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.

It most likely because SQLite is not a managed dll, it is compiled to a specific CPU.

System.Data.SQLite does not change this behavior since it is just a wrapper and container for the unmanaged dll.

The easiest way to fix this is to change the platform target under build properties of the Visual Studio project to x86.

VSProjectPropertiesBuild

Another alternative is to choose the x64 version of System.Data.SQLite, but if the same source code is used on both x86 and x64 it is not option.

2008-03-27

NHibernates MemCached feature

Getting started

NHibernate have rich support for caching, one of them is memcached. Getting started was actually easy, I followed this guide.

Download the sample

The VS2005 solution can be downloaded here. It is based on NHibernate NHibernate-1.2.1.GA-src.zip and SQL CE is included.

Using the sample

Memcahed Win32 is included in the solution and 2 instances can be started with memcached1.bat and memcached2.bat. Any activity can be monitored in the console windows.

NHibernate logs to a file called "NHibernateCacheExampleClient\log4net.log", and you should be able to see SQL executed against the database here.

The "Create" button creates a new Person with Id "1" and the name "John Doe". 
The "Get" button loads a Person with Id "1".

If the cache is running and the Person is in the cache, the NHibernate log should not show any SQL execute and the memcached console should show activity.

2008-03-26

NHibernates Search feature

Ayende wrote about Googlize your entities: NHibernate & Lucene.NET Integration, but the only documentation I could find was this blog post.

I have created a sample application, using the NHibernate NHibernate-1.2.1.GA-src.zip and build it with NAnt in release mode. It uses SQL CE, so everything is packed in the file.

Download it here

2008-03-21

NHibernates SchemaUpdate feature

Ayende wrote about Setting Up Zero Friction Projects - Data Access, and mentioned the new SchemaUpdate feature in NHibernate.

The idea being that the ddl is automagically created from the nhibernate hbm.xml files, and executed against the delvelopers local database.

Something like:

  1. Developer A changes the Order.hbm.xml where he adds a new field Discount.
  2. In ApplicationStart the ddl alter script is generated and executed against Developer A's local database, the next time the developer starts the application.
  3. Developer eventually does a check-in of the Order.hbm.xml, along with the other changes.
  4. Developer B does a get latest.
  5. When he starts the application, ApplicationStart executes the change dll, and now Developer B's local database is up to speed.

At what cost? Well, almost zero :-)

I have created a sample C# VS2008 Solution, that can be downloaded here.