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

  • Home
  • SEARCH
  • 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 7793187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:24:22+00:00 2026-06-01T22:24:22+00:00

I use Fluent NHibernate and have to work with archived data right now, where

  • 0

I use Fluent NHibernate and have to work with archived data right now, where the same table exists on multiple MSSQL Databases. Depending on a user provided Date value, I have to connect to a different Database, whereas all Mapping information remains the same.

More specific : if the provided Date value is within the current year, use DB CUR, otherwise use an annual DB (2011, 2010, 2009,…).

Now there was a time when people told me that re-creating a SessionFactory over and over is quite an expensive thing to do, so I thought to myself that there must be a way to use the existing sessionFactory, Update my ClassMap (something like change Schema from “CUR.DBO” to “2011.DBO”) and reconnect.

I tried mess with both FluentConfiguration and SessionFactory, but then I took an arrow in the knee couldn’t find a way to refresh the mappings at runtime.

Will I end up creating a new SessionFactory? Or does anyone out there know a viable procedure to reinitialize (Fluent) NHibernate’s mappings at runtime?

EDIT: One very important detail, the SqlConnection is provided externally, too. It provides access to all databases, meaning that, in theory, I’ll never have to create Connections. So, basically what I have to do is create a SessionFactory for each Archive to update the Mapping’s Schema information, pointing to another database. But this is exactly where I’m stuck.

  • 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-01T22:24:24+00:00Added an answer on June 1, 2026 at 10:24 pm

    Thanks for your responses / comments. Actually I haven’t found a way to reuse the session factory, so I ended up creating a lookup list for them as proposed. The following solution does what I need (change the database), we shall how it performs:

        private IDictionary<string, ISessionFactory> _sessionFactories;
    
        public SqlConnection Connection { get; set; }
    
        public ISessionFactory GetSessionFactory(string dbName)
        {
            if (_sessionFactories.ContainsKey(dbName))
            {
                return _sessionFactories[dbName];
            }
    
            FluentConfiguration cfg = Fluently.Configure().Database(MsSqlConfiguration.MsSql2008
                                                                    .ShowSql()
                                                                    .ConnectionString(c=>c.Is(Connection.ConnectionString)))
                                                          .Mappings(x=>x.FluentMappings.Add<MappedClassMap>());
            cfg.ExposeConfiguration(x => x.GetClassMapping(typeof(MappedClass)).Table.Schema = string.Format("{0}.dbo",dbName));
            ISessionFactory sf = cfg.BuildSessionFactory();
            _sessionFactories.Add(dbName, sf);
            return sf;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Fluent nHibernate data tier that I would like to use in
I am trying to use Fluent NHibernate. I have setup two table Products and
I am changing my application to use Fluent NHibernate. I have created my Fluent
I have a weird reference error when I use Fluent NHibernate 1.0 RTM and
I have this Fluent NHibernate mapping: public LossMap() { Table(losses); Id(x => x.Id).Column(id); References(x
Is it possible to use Fluent NHibernate's PersistenceSpecification to test NHibernate mappings done via
I am new to nHibernate. I understand how to use mapping using Fluent nHibernate.
How would I use nHibernate,configured by fluent nhibernate if it makes any difference, to
I've been trying to use #harp architecture and Fluent-NHibernate. I am trying to sublass
Is it possible to use something like this wrapper with fluent configuration? http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/ If

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.