Question

I have a ASP.NET MVC 4 application. It uses Spring.net and Nhibernate 3.2. Configurations are done by xml files.

Recently I got into Nhibernate's Mapping by code new feature. I'm trying to implement it in my current application, so ClassMapping's will be configured and scheme will be updated according to that.

I couldn't achieve this, making some changes in my xml configurations.

Here's my NHibernate configuration

<object id="NHibernateSessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate32">
    <property name="MappingAssemblies">
      <list>
        <value>CM.Data.NHibernate</value>
      </list>
    </property>
    <property name="DbProvider" ref="DbProvider"/>

    <property name="HibernateProperties">
      <dictionary>
        <entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
        <entry key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
        <entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
        <entry key="hbm2ddl.auto" value="update"/>
        <entry key="hbm2ddl.keywords" value="auto-quote"/>
        <entry key="show_sql" value="true"/>
        <entry key="adonet.batch_size" value="0"/>
        <entry key="hibernate.current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate32"/>
      </dictionary>
    </property>
    <property name="ExposeTransactionAwareSessionFactory" value="true" />
  </object>

Sample mapping class

namespace CM.Data.NHibernate
{
    public class DynamicEntityMap : ClassMapping<DynamicEntity>
    {
        public DynamicEntityMap()
        {
            Id(x => x.Id);
        }
    }

    public class DynamicEntity
    {
        public virtual int Id { get; set; }
    }
}

It doesn't seem to work. Table is not generated.

Am I missing something? I was thinking to override LocalSessionFactoryObject as it was done for FNH in the link below. Would it work for me also? I'm not sure if it won't break transaction management or something else.

Please, give me some insights on this matter.

What's the best approach in this situation?

Using Fluent NHibernate in Spring.Net

Was it helpful?

Solution

Currently is not supported by Spring .Net as you can see here

You can try Marijn implementation, this should work without break anything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top