如何配置FluentNHibernate不覆盖现有的SQLite数据库文件? [英] How do I configure FluentNHibernate to not overwrite an existing SQLite db file?

查看:143
本文介绍了如何配置FluentNHibernate不覆盖现有的SQLite数据库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的配置:

  this.factory =流利的.Configure()。 
数据库(SQLiteConfiguration.Standard.UsingFile(foo.db)。
ShowSql())。
映射(m => m.FluentMappings.AddFromAssemblyOf< Bar>())。
ExposeConfiguration(BuildSchema)。
BuildSessionFactory();

BuildSchema看起来像这样:

<$ p $私人静态无效的BuildSchema(配置配置)
{$ b $新的SchemaExport(config).Create(false,true);
}

幸运的是,这个工作很好,创建了一个名为foo.db的文件,我可以读和写。不幸的是,每次我运行这个代码,foo.db都被覆盖。如何配置(流利)NHibernate创建文件,只有当它不存在?

解决方案

把一个if语句在你的BuildSchema?

  if(!File.Exists(foo.db))
新的SchemaExport(config ).Create(false,true);


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?

解决方案

Put an if statement in your BuildSchema?

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

这篇关于如何配置FluentNHibernate不覆盖现有的SQLite数据库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆