How to configure FluentNHibernate to not overwrite an existing SQLite db file?

Here is my configuration:

this.factory = Fluently.Configure().
    Database(SQLiteConfiguration.Standard.UsingFile("foo.db").
        ShowSql()).
    Mappings(m => m.FluentMappings.AddFromAssemblyOf<Bar>()).
    ExposeConfiguration(BuildSchema).
    BuildSessionFactory();

BuildSchema is as follows:

private static void BuildSchema(Configuration config)
{
    new SchemaExport(config).Create(false, true);
}

Fortunately, this works great and creates a file called foo.db that I can read and write. Unfortunately, every time I run this code, foo.db is overwritten. How can I configure (Fluent) NHibernate to create a file only if it does not already exist?

+2
source share
1 answer

Put an if statement in your BuildSchema?

if (!File.Exists("foo.db"))
  new SchemaExport(config).Create(false, true);
+8
source

All Articles