Setting the sessionfactory name using fnh

He Zhu's Avatar

He Zhu

13 Sep, 2010 02:06 PM via web

Hi,

Is there no way to set the SessionFactory's name using Fluent NHibernate? If not, is there a way to export that part of the NH configuration? I couldn't find a way to do this either.

Thanks

  1. Support Staff 2 Posted by Paul Batum on 15 Sep, 2010 04:57 PM

    Paul Batum's Avatar

    You can always use the normal nhibernate supported ways of providing your
    configuration. Your not limited to what our fluent interface offers.

    From our wiki (http://wiki.fluentnhibernate.org/Database_configuration) :

    Using Fluent NHibernate does not require you to sacrifice portability across
    RDBMSes. You can use the traditional approach to NHibernate configuration
    (which uses the standard .NET configuration mechanisms) to determine
    database drivers and connection strings this way:

    var cfg = new NHibernate.Cfg.Configuration();
    cfg.Configure(); // read config default style
    Fluently.Configure(cfg)
        .Mappings(
          m => m.FluentMappings.AddFromAssemblyOf<Entity>())
        .BuildSessionFactory();

    On Mon, Sep 13, 2010 at 7:08 AM, He Zhu <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  2. 3 Posted by He Zhu on 15 Sep, 2010 09:08 PM

    He Zhu's Avatar

    Fantastic! Just the thing I was looking for. Completely missed that section of the wiki xD

    Thanks a lot.

  3. 4 Posted by He Zhu on 16 Sep, 2010 08:52 AM

    He Zhu's Avatar

    Hi, just a heads up:

    I used the following code to set the session factory name but it didn't work. The NH cfg recognises the name but after I passed it to Fluently.Configure, the resulting factory has Name null. I dug around and found the property is called "session_factory_name" and used ExposeConfiguration SetProperty to get around it.

    Is this a bug?

    hibernate.cfg.xml
    ` <?xml version="1.0" encoding="utf-8" ?>

    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />

    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

    <session-factory name="factory">
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    </session-factory>

    </hibernate-configuration>
    `

    code
    ` var cfg = new NHibernate.Cfg.Configuration();
    cfg.Configure();

    return Fluently.Configure(cfg)

                .Database(
                    MsSqlConfiguration.MsSql2005.ConnectionString(Settings.Const_ConnectionString)
                 )
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Lion>())
                .BuildSessionFactory();

    `

  4. Support Staff 5 Posted by Paul Batum on 19 Sep, 2010 01:55 AM

    Paul Batum's Avatar

    Oh I didn't realise that we had a way to set the session factory name from
    our fluent interface. I had a quick look beforehand and failed to find it.

    It does seem somewhat undesirable that we might overwrite someone's config
    setting with our own blank one. I wonder if this is an isolated bug or if
    this is happening with other configuration settings as well...

    On Thu, Sep 16, 2010 at 1:55 AM, He Zhu <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What month comes before July?