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

问题描述 投票:0回答:2

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

  • 可以使用ALTER TABLE生成Fluent Nhibernate Schema Export语句而不是CREATE TABLE吗?
fluent-nhibernate
2个回答
2
投票

肯定是可能的

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

0
投票

创建一个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);
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.