I saw various blog posts about nHibernate SchemaUpdateand even a Ayende'svery good example and uploaded samples, but for some reason I cannot get the same thing as for me. I note that I use Fluent NHibernate, but from what I can say, there should not be too much difference.
Update
I have reached the point at which it is executed SchemaUpdate, but this is just a complete creation of the circuit, not a "change." In other words, it is the same as if I just created a database. I publish my complete source below.
Here is what I'm basically trying ... I think this is generally obvious, but basically I create an object Configurationusing Fluent Configuration, and then try to pass it. Unit tests pass, programs start ... but nothing really happens. I never see any results, and I never see the database schema being updated.
Database is created (missing columns, etc.)
Then the database is then mapped to the new schema the next time it starts.
The database (update) must update the schema using the update method.
But this is not what is actually happening.
I also looked at other posts on this subject. Like here: http://morten.lyhr.dk/2008/03/nhibernates-schemaupdate-feature.html
,
NHibernate
.
private static void UpdateSchema(NHibernate.Cfg.Configuration Config) {
System.Action<string> updateExport = x => {
using (var file = new System.IO.FileStream(@"C:\Users\User\Documents\Visual Studio 2010\Mappings\update.sql", System.IO.FileMode.Append, System.IO.FileAccess.Write))
using (var sw = new System.IO.StreamWriter(file)) {
sw.Write(x);
sw.Close();
}
};
NHibernate.Tool.hbm2ddl.SchemaUpdate SchemaUpdater = new NHibernate.Tool.hbm2ddl.SchemaUpdate(Config);
SchemaUpdater.Execute(updateExport, false);
}
public static ISessionFactory Map(string connectionString) {
return FluentNHibernate.Cfg.Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.Is(connectionString))
.AdoNetBatchSize(50)
.FormatSql()
.UseReflectionOptimizer())
.Cache(c => c
.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider>()
.UseQueryCache()
.UseSecondLevelCache()
.UseMinimalPuts())
.Mappings(m => {
m.FluentMappings.Conventions.Setup(x => {
x.AddFromAssemblyOf<Mappings.AspectMap>();
x.Add<EnumConvention>();
x.Add(FluentNHibernate.Conventions.Helpers.AutoImport.Never());
});
m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly());
})
.ExposeConfiguration(UpdateSchema)
.BuildSessionFactory();
}