Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate ClassMappings = 0
    text
    copied!<p>I am trying to user NHibernate / FluentNHibernate to create a table in my database. I seem to have figured it out for the most part but when I run the test the table isn't created. I see in the Configuration object that the ClassMappings is a big fat zero even thought I have user FluentNHibernate to configure them from an assembly. I somewhat understand this but I am missing some connection somewhere... Here is the code snippets, maybe someone can see what I forogt? </p> <p>Here is my dataconfig class. </p> <pre><code>public static FluentConfiguration GetFluentConfiguration() { string hibernateCfgFile = @"C:\Users\kenn\Documents\Visual Studio 2008\Projects\NHibernateTestTwo\Infrastructure\hibernate.cfg.xml"; return Fluently.Configure(new Configuration().Configure(@hibernateCfgFile)) .Mappings(cfg =&gt; cfg.FluentMappings.AddFromAssembly(typeof(AddressMap).Assembly)); } </code></pre> <p>Here is the test class. </p> <pre><code>[Test, Explicit] public void SetupDatabase() { FluentConfiguration conf = DataConfig.GetFluentConfiguration(); conf.ExposeConfiguration(BuildSchema).BuildSessionFactory(); } private static void BuildSchema(Configuration conf) { new SchemaExport(conf).SetOutputFile("drop.sql").Drop(false, true); new SchemaExport(conf).SetOutputFile("create.sql").Create(false, true); } </code></pre> <p>Here is the mappings</p> <pre><code> public AddressMap() { Table("Address"); DynamicUpdate(); Id(a =&gt; a.Id).GeneratedBy.GuidComb(); Map(a =&gt; a.AddressOne).Not.Nullable().Length(100); Map(a =&gt; a.AddressTwo).Length(100); Map(a =&gt; a.City).Not.Nullable().Length(100); Map(a =&gt; a.state).Not.Nullable().Length(100); Map(a =&gt; a.zip).Not.Nullable().Length(50); Map(a =&gt; a.Primary).Not.Nullable(); } </code></pre> <p>The hibernate.cfg.xml file</p> <pre><code>&lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt; &lt;session-factory&gt; &lt;property name="connection.driver_class"&gt; NHibernate.Driver.SqlClientDriver &lt;/property&gt; &lt;property name="connection.connection_string"&gt; Data Source=MYPC;Initial Catalog=NHibernateSample;Integrated Security=True; &lt;/property&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;property name="dialect"&gt; NHibernate.Dialect.MsSql2005Dialect &lt;/property&gt; &lt;property name="adonet.batch_size"&gt;100&lt;/property&gt; &lt;!--&lt;property name="proxyfactory.factory_class"&gt; NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu &lt;/property&gt;--&gt; &lt;property name="proxyfactory.factory_class"&gt; NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle &lt;/property&gt; &lt;/session-factory&gt; </code></pre> <p></p> <p>I am just not sure what is missing there... It clearly is talking to the DB cause if I change the name of the database to something that doesn't exist it trows an exception, I am stuck - I have gone round and round on this and just haven't figured it out yet so any help would be greatly appreciated. </p> <p>Thanks! </p>
 

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