问题
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 looks like this:
private static void BuildSchema(Configuration config)
{
new SchemaExport(config).Create(false, true);
}
Luckily this works great and creates a file named foo.db to which I can read and write. Unluckily, every time i run this code, foo.db is overwritten. How can I configure (Fluent)NHibernate to create the file only if it doesn't already exist?
回答1:
Put an if statement in your BuildSchema?
if (!File.Exists("foo.db"))
new SchemaExport(config).Create(false, true);
来源:https://stackoverflow.com/questions/1253474/how-do-i-configure-fluentnhibernate-to-not-overwrite-an-existing-sqlite-db-file