Kenn
Kenn

Reputation: 2769

NHibernate ClassMappings = 0

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?

Here is my dataconfig class.

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 => cfg.FluentMappings.AddFromAssembly(typeof(AddressMap).Assembly));
    }

Here is the test class.

[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);
    }

Here is the mappings

 public AddressMap()
    {

        Table("Address");
        DynamicUpdate();
        Id(a => a.Id).GeneratedBy.GuidComb();
        Map(a => a.AddressOne).Not.Nullable().Length(100);
        Map(a => a.AddressTwo).Length(100);
        Map(a => a.City).Not.Nullable().Length(100);
        Map(a => a.state).Not.Nullable().Length(100);
        Map(a => a.zip).Not.Nullable().Length(50);
        Map(a => a.Primary).Not.Nullable();

    }

The hibernate.cfg.xml file

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
    <property name="connection.driver_class">
        NHibernate.Driver.SqlClientDriver
    </property>
    <property name="connection.connection_string">
        Data Source=MYPC;Initial Catalog=NHibernateSample;Integrated Security=True;
    </property>
    <property name="show_sql">true</property>
    <property name="dialect">
        NHibernate.Dialect.MsSql2005Dialect
    </property>
    <property name="adonet.batch_size">100</property>
    <!--<property name="proxyfactory.factory_class">
        NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
        NHibernate.ByteCode.LinFu
    </property>-->
    <property name="proxyfactory.factory_class">
        NHibernate.ByteCode.Castle.ProxyFactoryFactory, 
        NHibernate.ByteCode.Castle
    </property>
</session-factory>

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.

Thanks!

Upvotes: 0

Views: 271

Answers (1)

Kenn
Kenn

Reputation: 2769

See my comment... Don't forget to make your map classes public or FluentNHibernate won't see them.

Upvotes: 1

Related Questions