首页 文章

导出流畅的Nhibernate模式和更改表

提问于
浏览
0

我能够从Fluent Nhibernate生成并导出模式创建脚本 . 有时我想修改一些字段或在创建模式后向表中添加新字段而不删除所有表 . 我现在做的是生成第一个模式脚本,然后在开发过程中手动添加或修改数据库 .

  • 可以使用ALTER TABLE而不是CREATE TABLE使用Fluent Nhibernate Schema Export语句生成?

2 回答

  • 0

    肯定是可能的

    new SchemaUpdate(config).Execute(true, true);
    
  • 2

    创建一个Action并将其传递给SchemaUpdate方法

    string script = "LogFile.txt"
    if (!File.Exists(script))
        File.Create(script);
    
    // writes out an alter table script
    Action<string> updateLogFile= x =>
    {
        //Open up file, append
        using (var file = new FileStream(script, FileMode.Append))
        {
            //Write each line
            using (var sw = new StreamWriter(file))
            {
                sw.Write(x);
                sw.Close();
            }
        }
    };
    
    // Perform Schema update into updateLogFile Action
    new SchemaUpdate(config)
        .Execute(updateLogFile, true);
    

相关问题