Note that there are some explanatory texts on larger screens.

plurals
  1. POStruggling to Comprehend nHibernate SchemaUpdate, even with Blog Posts
    primarykey
    data
    text
    <p>I've seen the various blog posts concerning nHibernate's <code>SchemaUpdate</code>, and even <code>Ayende's</code> very good example, and downloaded the samples, but for some reason I cannot get the same same thing to work for me. I will note that I am using <code>Fluent NHibernate</code>, but from what I can tell that should not make too huge a difference.</p> <h2>Update</h2> <blockquote> <p>I have reached the point where the <code>SchemaUpdate</code> runs, but it is just a full schema creation, no 'altering'. In otherwords, it's the same as if I just built the database fresh. I am posting my full source below.</p> </blockquote> <p>Here Is what I am basically trying... I think it is generally self obvious, but basically I am creating a <code>Configuration</code> object using the Fluent Configuration, and then trying to pass it in. Unit Tests pass, programs run ...but nothing actually happens. I can never see any results, and I can never see the database schema get updated. </p> <blockquote> <p>Database gets created (missing columns, etc)</p> <p>Database then gets mapped with new schema on next run.</p> <p>Database (Update) should update the Schema per the Update method.</p> </blockquote> <p>But that isn't what is actually happening.</p> <p>I also looked at other posts on the matter. Like here : <a href="http://morten.lyhr.dk/2008/03/nhibernates-schemaupdate-feature.html" rel="nofollow noreferrer">http://morten.lyhr.dk/2008/03/nhibernates-schemaupdate-feature.html</a></p> <p>Additionally, I have changed my code after finding the following Stack Overflow post <a href="https://stackoverflow.com/questions/2483424/make-fluent-nhibernate-output-schema-update-to-file">Make Fluent NHibernate output schema update to file</a></p> <p>And even with the sample code was not able to make heads or tails of this feature.</p> <h2>Code</h2> <pre><code> private static void UpdateSchema(NHibernate.Cfg.Configuration Config) { System.Action&lt;string&gt; updateExport = x =&gt; { 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) { // fluently configure an ms-sql 2008 database return FluentNHibernate.Cfg.Fluently.Configure() .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008 .ConnectionString(c =&gt; c.Is(connectionString)) .AdoNetBatchSize(50) .FormatSql() .UseReflectionOptimizer()) .Cache(c =&gt; c .ProviderClass&lt;NHibernate.Caches.SysCache2.SysCacheProvider&gt;() .UseQueryCache() .UseSecondLevelCache() .UseMinimalPuts()) .Mappings(m =&gt; { m.FluentMappings.Conventions.Setup(x =&gt; { x.AddFromAssemblyOf&lt;Mappings.AspectMap&gt;(); x.Add&lt;EnumConvention&gt;(); x.Add(FluentNHibernate.Conventions.Helpers.AutoImport.Never()); }); m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()); }) .ExposeConfiguration(UpdateSchema) .BuildSessionFactory(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload