views:

418

answers:

1

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

Public Sub UpdateBaseFiles()
    Dim db As SQLiteConfiguration
    db = SQLiteConfiguration.Standard.UsingFile(BASE_DBNAME)
    Fluently.Configure() _
            .Database(db) _
            .Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of FluentMap)()) _
            .ExposeConfiguration(AddressOf UpdateSchema) _
            .BuildConfiguration()
End Sub
Private Sub UpdateSchema(ByVal Config As Configuration)
    Dim SchemaUpdater As New SchemaUpdate(Config)
    SchemaUpdater.Execute(True, True)
End Sub

How do I output the DDL to a file, I do this when initially creating the schema by using:

Private Sub BuildSchema(ByVal Config As Configuration)
    Dim SchemaExporter As New SchemaExport(Config)
    SchemaExporter.SetOutputFile("schema.sql")
    SchemaExporter.Create(False, True)
End Sub

but SchemaUpdate does not have a SetOutputFile method.

+3  A: 

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.Write))
        using (var sw = new StreamWriter(file))
        {
            sw.Write(x);
            sw.Close();
        }
    };
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.

Jamie Ide
I am sure this would work in C#, but I am having trouble translating the delegate template into VB, any ideas?
Bender
I'm not sure you can, see http://stackoverflow.com/questions/892021/actionof-t-in-visual-basic-in-listof-t-foreach.
Jamie Ide