I read a few examples on how to use NHibernate with SQLite, and most of them relate to CRUD operations with unit testing and all that. So, the examples that I have encountered and followed so far are related to this. This is good, but the problem is that every time I run my program, the database is recreated! How can I change my code so that if the database already exists, NHibernate will NOT create it? And yes, I tried to check with File.Exists, but it ignored; I believe it because NHibernate gets to the file first.
This is my mapping:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory name="NHibernate.Test"> <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> <property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <property name="query.substitutions">true=1;false=0</property> <property name="show_sql">false</property> </session-factory> </hibernate-configuration>
And my complete code:
using System; using System.Collections.Generic; using System.Data.SQLite; using System.Linq; using NHibernate; using NHibernate.Cfg; using PruebaNHLite.Domain; namespace PruebaNHLite { public class Program { public static ISession sess; public static Configuration cfg; public static SQLiteConnection connection; private const string CONNECTION_STRING = @"Data Source=nhlite.db;Pooling=true;FailIfMissing=false; BinaryGUID=false;New=false;Compress=true;Version=3"; static void Main(string[] args) { Init(); BuildSchema(); Insert(); Retrieve(); sess.Close(); sess = null; } public static void Init() {
CMPerez
source share