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

老子叫甜甜 提交于 2019-12-20 03:19:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!