Make Fluent NHibernate output schema update to file

后端 未结 2 2024
醉梦人生
醉梦人生 2021-02-13 20:21

I am successfully getting Fluent NHibernate to update my database by calling UpdateBaseFiles:

Public Sub UpdateBaseFiles()
    Dim db As SQLiteConfiguration
            


        
相关标签:
2条回答
  • 2021-02-13 21:05

    SchemaUpdate has an overload that accepts an Action<string> delegate that you can supply to export the script. Here's an example in C#:

    Action<string> updateExport = x =>
        {
            using (var file = new FileStream(path, FileMode.Create, FileAccess.Append))
            using (var sw = new StreamWriter(file))
            {
                sw.Write(x);
            }
        };
    new SchemaUpdate(config).Execute(updateExport, false);
    

    I think that will work. I wasn't able to test it because SchemaUpdate is not working with SQLCE.

    0 讨论(0)
  • 2021-02-13 21:10

    SchemaUpdate calls the action for each update it does so you dont want to be recreating (and therefore overwriting) the same file on each command as above, this is what is required:

    using (var file = new FileStream(@"..\..\..\schema-update.sql",
           FileMode.Create,
           FileAccess.ReadWrite))
    using (var sw = new StreamWriter(file))
    {
       new SchemaUpdate(config)
           .Execute(sw.Write, false);
    }
    
    0 讨论(0)
提交回复
热议问题