Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:49:10+00:00 2026-06-11T23:49:10+00:00

I have an application using NHibernate and I’m using Fluent NHibernate to mapping my

  • 0

I have an application using NHibernate and I’m using Fluent NHibernate to mapping my entities. It works fine, but, I want to create the SessionFactory using the native way of NHibernate because my team will ues this library on other projects, so we need this flexibilty to move the nhibernate.cfg.xml. My question is: How can I set the Fluent Mappings in the configuration of SessionFactory with native way of nhibernate?

I try something like this on my configuration method:

private static ISessionFactory Configure()
{
    if (_factory != null)
        return _factory;

    var configuration = new Configuration().Configure();

        // I could set my assembly of mapping here, but it's on our internal framework
    var fluentConfiguration = Fluently.Configure(configuration)
        //.Mappings(c => c.FluentMappings.AddFromAssembly(typeof(ProductMap)))
        .BuildConfiguration();

    _factory = fluentConfiguration.BuildSessionFactory();

    return _factory;
}

I tried to set it by xml, but it does not work.

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>     
        <!-- other configs here...-->     
        <mapping assembly="MyApplication.Data.Mapping" />
    </session-factory>
</hibernate-configuration>

I don’t know if is there any way to get this mapping setted on the xml and pass to FluentConfiguration declaration on my method to create the ISessionFactory.

Thank you guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:49:12+00:00Added an answer on June 11, 2026 at 11:49 pm

    The mapping in the config does not work because it will not consider Fluentmappings (Nhibernate does not know FluentNhibernate). You have to set it by code. Best option i can think of is to implement a hook to alter the config object before building the sessionfactory:

    private static ISessionFactory Configure()
    {
        if (_factory != null)
            return _factory;
    
        var configuration = new Configuration().Configure();
    
        foreach(var alteration in alterations)
        {
            alteration.AddTo(configuration);
        }
    
        _factory = fluentConfiguration.BuildSessionFactory();
    
        return _factory;
    }
    
    // in your alteration
    Configuration AddTo(Configuration config)
    {
        return Fluently.Configure(config)
                   .Mappings(c => c.FluentMappings.AddFromAssembly(typeof(ProductMap)))
                   .BuildConfiguration();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF Application using Fluent NHibernate 1.0 RTM and System.Data.SQLite 1.0.65 that
I have a ASP.NET MVC application using NHibernate and the application runs fine when
I am building .net application using nhibernate for mapping data to entities. I am
I have an application using Fluent NHibernate on the server side to configure the
I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
I have an asp.net mvc2 application that is using StructureMap 2.6 and NHibernate 3.x.
I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
I'm using: Hibernate MySQL jBoss I have to create an application that allows user
I have Silverlight application using NHibernate as a ORM. I have projects for Data(mapp
I have a WPF application running with VS2010 .Net3.5 using Nhibernate with FluentNHibernate +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.