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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:59:10+00:00 2026-05-15T00:59:10+00:00

Noob question. I have this situation where I have these objects: class Address {

  • 0

Noob question.

I have this situation where I have these objects:

class Address
{      
   string Street;
   string City;
   ...
}

class User
{
   string UserID;
   Address BillingAddress;
   Address MailingAddress;
   ...
}

What is the proper way of storing this data using (fluent) nHibernate? I could use a separate Address table and create a reference, but they are 1:1 relationships so I don’t really want to incur the overhead of a join. Ideally I would store this as a single flat record.

So, my question is, what is the proper way of storing an instance of class ‘User’ in such a way that it stores its contents and also the two addresses as a single record? My knowledge is failing me on how I can store this information in such a way that the two Address records get different column names (e.g. BillingAddress_Street and MailingAddress_Street, for example), and also how to read a record back into a User instance.

  • 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-05-15T00:59:10+00:00Added an answer on May 15, 2026 at 12:59 am

    These kinds of structures are referred to as a component. They’re a normalized structure, and perfectly acceptable mechanism for representing data.

    In Fluent NHibernate there are a couple of ways to map components. Firstly there’s inline mappings, and then the external ComponentMap. I would recommend the latter in your situation, and in any scenario where you have a component that appears multiple times (either in the same entity, or across your domain).


    Inline Components

    To map a component, the simplest way is to use the Component method and specify how the component is composed using the body lambda.

      Component(x => x.BillingAddress, addr =>
      {
        addr.Map(x => x.Street);
        addr.Map(x => x.City);
      });
    

    That’s your address mapped. You’ll need to repeat this for both addresses.


    ComponentMap

    The inline definition works fine for one-off components, but it can quickly become tiresome when you have multiple instances of the same component. ComponentMap solves this by extracting your component out into a self-contained, reusable, definition. You just use it exactly the same way as you do ClassMap.

    public class AddressMap : ComponentMap<Address>
    {
      public AddressMap()
      {
        Map(x => x.Street);
        Map(x => x.City);
      }
    }
    

    Then in your ClassMap, you just need to use the bodyless Component method; this instructs Fluent NHibernate to search for a ComponentMap matching the type of the property (if one isn’t found, you’ll know about it).

    Component(x => x.BillingAddress);
    Component(x => x.MailingAddress);
    

    With the ComponentMap, column prefixes are automatically created as necessary based on the property that contains the component. If you need to customise this there’s the ColumnPrefix method that’s chained off the bodyless Component call.

    Component(x => x.BillingAddress)
      .ColumnPrefix("Billing_");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.