Using NHibernate and Mono.Data.SQLite Using NHibernate and Mono.Data.SQLite sqlite sqlite

Using NHibernate and Mono.Data.SQLite


There is a problem in the answer of Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite . For the given constructor (3 parameters) to work the assembly in question (Mono.Data.Sqlite) needs to be loaded first.

This works if the 4-parameter base contructor is used like this:

public class MonoSQLiteDriver : NHibernate.Driver.ReflectionBasedDriver  {          public MonoSQLiteDriver()             : base(            "Mono.Data.Sqlite",            "Mono.Data.Sqlite",              "Mono.Data.Sqlite.SqliteConnection",              "Mono.Data.Sqlite.SqliteCommand")      {      }      public override bool UseNamedPrefixInParameter {          get {              return true;          }      }      public override bool UseNamedPrefixInSql {          get {              return true;          }      }      public override string NamedPrefix {          get {              return "@";          }      }      public override bool SupportsMultipleOpenReaders {          get {              return false;          }      }  }  

(Still, credit goes to http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx for the original idea - thanks.)

And if you use FluentNHibernate, then you'll also need:

public class MonoSQLiteConfiguration : PersistenceConfiguration<MonoSQLiteConfiguration>{    public static MonoSQLiteConfiguration Standard    {        get { return new MonoSQLiteConfiguration(); }    }    public MonoSQLiteConfiguration()    {        Driver<MonoSQLiteDriver>();        Dialect<SQLiteDialect>();        Raw("query.substitutions", "true=1;false=0");    }    public MonoSQLiteConfiguration InMemory()    {        Raw("connection.release_mode", "on_close");        return ConnectionString(c => c            .Is("Data Source=:memory:;Version=3;New=True;"));    }    public MonoSQLiteConfiguration UsingFile(string fileName)    {        return ConnectionString(c => c            .Is(string.Format("Data Source={0};Version=3;New=True;", fileName)));    }    public MonoSQLiteConfiguration UsingFileWithPassword(string fileName, string password)    {        return ConnectionString(c => c            .Is(string.Format("Data Source={0};Version=3;New=True;Password={1};", fileName, password)));    }}

I have not encountered any problems so far...