因某项目需移动到JEXUS上,该项目采用的是SQLITE + Nhibernate结构
在移植的过程中出现了一些问题,特此记录
首先System.Data.Sqlite在MONO下是不能用的
并且Nhibernate的配置文件引用的驱动类NHibernate.Driver.SQLite20Driver是不支持的
所以我们要对以上几点进行修改
1. 添加 MonoSQLiteDriver 类
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; } } }
2. 将hibernate.cfg.xml 里的connection.driver_class节点的值,改成步骤1里的类, 即 YourNameSpace.MonoSqliteDriver, AssemblyName
如: <property name="connection.driver_class">xxxxx.MonoSqliteDriver, xxxxxxx</property>
如果使用FluentNHibernate, 还需要如下
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))); } }
3. 用Nuget添加Mono.Data.Sqlite的引用
这样就把IIS+SQLite+Nhibernate的环境移植到Jexus+Sqlite(MONO)+Nhibernate上了.