使 Fluent NHibernate 输出模式更新到文件
我成功地让 Fluent NHibernate 通过调用 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
如何将 DDL 输出到文件来更新我的数据库,我在最初使用以下方法创建架构时执行此操作:
Private Sub BuildSchema(ByVal Config As Configuration)
Dim SchemaExporter As New SchemaExport(Config)
SchemaExporter.SetOutputFile("schema.sql")
SchemaExporter.Create(False, True)
End Sub
但 SchemaUpdate 没有 SetOutputFile 方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SchemaUpdate 具有接受
Action
委托的重载,您可以提供该委托来导出脚本。这是 C# 中的一个示例:我认为这会起作用。我无法测试它,因为 SchemaUpdate 不支持 SQLCE。
SchemaUpdate has an overload that accepts an
Action<string>
delegate that you can supply to export the script. Here's an example in C#:I think that will work. I wasn't able to test it because SchemaUpdate is not working with SQLCE.
SchemaUpdate
会为其执行的每个更新调用该操作,因此您不希望在每个命令上重新创建(并因此覆盖)与上述相同的文件,这是必需的: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: