本文介绍了使流畅的NHibernate输出模式更新到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
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)_ $ b $ .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.SetOutput File(schema.sql)
SchemaExporter.Create(False,True)
End Sub
但SchemaUpdate没有SetOutputFile方法。
解决方案
SchemaUpdate有一个接受动作< string>
委托,您可以提供导出脚本。以下是C#中的一个例子:
动作< string> updateExport = x =>
{
using(var file = new FileStream(path,FileMode.Create,FileAccess.Append))
using(var sw = new StreamWriter(file))
{
sw.Write(x);
}
};
新SchemaUpdate(config).Execute(updateExport,false);
我认为这样可以。我无法测试它,因为SchemaUpdate是。 p>
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.
解决方案
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.
这篇关于使流畅的NHibernate输出模式更新到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!