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 8333547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:04:17+00:00 2026-06-09T03:04:17+00:00

We have a multi-tenant database – i.e. common database used by multiple clients, hence

  • 0

We have a multi-tenant database – i.e. common database used by multiple clients, hence each table will have a “ClientID” column indicating the Tenant.
We are using Fluent NHibernate for ORM and looking for the best approach to tackle multi-tenancy: each Mapping class needs to map ClientID, however, the value would come from the User Account object – i.e. from User Session of some sort.

Is there a nice and easy way to achieve this using Fluent NHibernate? If so, could you provide an example?

  • 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-09T03:04:20+00:00Added an answer on June 9, 2026 at 3:04 am

    I’m not entirely sure if this is what your asking but if you need each class to map to the ClientId, here’s one example.

    Basically, each class would have a UserAccount property or whatever class is going to store the user’s account information that has the ClientId property on it. Then in your Fluent NHibernate mapping, you can map the classes together using the References() method. See example below:

    public class UserAccount
    {
        public virtual int Id { get; set; }
    
        public virtual string Name { get; set; }
    
        public virtual IList<Bill> Bills { get; set; }
    }
    
    public class Bill
    {
        public virtual int BillId { get; set; }
    
        public virtual UserAccount User { get; set; }
    }
    
    public class UserAccount : ClassMap<UserAccount>
    {
        public UserAccount()
        {
            Id( x => x.Id ).Column( "ClientId" );
    
            Map( x => x.Name );
    
            HasMany( x => x.Bills );
        }
    }
    
    public class BillMap : ClassMap<Bill>
    {
        public BillMap()
        {
            Id( x => x.Id ).Column( "BillId" );
            References( x => x.User ).Column( "ClientId" );
        }
    }
    

    So in your Bill table, you would have a ClientId column which in database terms is really a foreign key referencing the UserAccount table’s primary key column which would also be named ClientId.

    If you are truly going to have a large amount of tables that are all going to have a ClientId column, you also have the option of abstracting that out to a base class that your entities inherit from that would already have the UserAccount property on it. You could do the same base class approach for your Fluent NHibernate mapping files as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a multi-tenant application I have a table with TenantId column. This table is
I have a multi-tenant MySQL database. For most things I use a tenant-id column
Hi we are building an multi tenancy solution where each tenant will have its
We have a multi-tenant system with a separate database per tenant (but with the
We have a multi-tenant system with multiple different levels of access--sometimes even for the
I have an application that uses the grails multi-tenant-core plug-in to host multiple versions
Working on a multi-tenant app where most of my models will have a tenant_id
I have a full multi-tenant database with TenantID's on all the tenanted databases. This
im running a multi tenant GAE app where each tenant could have from a
I am using Grails multi-tenant plugin with single-tenant mode. I have used spring security

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.