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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:09:35+00:00 2026-06-12T15:09:35+00:00

I thought I had this one pegged by mapping the intermediary table as a

  • 0

I thought I had this one pegged by mapping the intermediary table as a HasMany and between intermediary and child as HasOne, however HasOne expects to share a key. (No Inverse option.:[ )

Anyhow, the relational structure I have:

Address (Child)
AddressId
..Address Fields

AddressCustomer (Intermediary)
AddressCustomerId
AddressId
CustomerId

Customer (Parent)
CustomerId
..Customer Fields

Why I have this intermediary table instead of a normal 1-many? Because there will be other entities that will need to contain addresses. (I.e. Sites, etc.) They will have their own intermediary table so they can share the address table.

Mappings I have so far:

    public class CustomerAddressMap : ClassMap<CustomerAddress>
{
    public CustomerAddressMap()
    {
        Schema("dbo");
        Table("CustomerAddress");
        Id(x => x.CustomerAddressId);
        Map(x => x.FromDate)
            .Not.Nullable();
        Map(x => x.ToDate);
        HasOne(x => x.Address)
            .ForeignKey("AddressId")
            .Cascade.All();
    }

}

public class AddressMap : ClassMap<Address>
{
    public AddressMap()
    {
        Schema("dbo");
        Table("Address");
        Id(x=>x.AddressId);
        Map(x => x.AddressType);
    }
}

With a null-able AddressId column in the CustomerAddress table, rows are inserted, however the AddressID from the Address row doesn’t propagate back up to CustomerAddress. There is no Inverse option on HasOne so that seems to be a dead end. I cannot have the Address ID generated on CustomerAddress because this would result in duplicates once I add something like SiteAddress and have to do the same thing. That trick may work with GUIDs as keys, but I’m stuck with auto-increment Ints for the moment.

Some other ideas I was noodling over was mapping a merge of CustomerAddress and Address but I don’t believe that is supported with Fluent NHibby.

I figure it’s a problem domain that someone has successfully applied. Essentially I want a 1-Many relationship where the child table (not it’s records) is shared between multiple parents. Any ideas?

  • 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-12T15:09:36+00:00Added an answer on June 12, 2026 at 3:09 pm

    map it as normal references

    public class CustomerAddressMap : ClassMap<CustomerAddress>
    {
        public CustomerAddressMap()
        {
            Table("CustomerAddress");
    
            Id(x => x.CustomerAddressId);
            Map(x => x.FromDate).Not.Nullable();
            Map(x => x.ToDate);
            References(x => x.Customer, "CustomerId");
            References(x => x.Address, "AddressId");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I had this one pretty good, but I just keep running into
Just when I thought I had this one cinched, I realized that I can
I thought I had this one sorted but I have run into a snag.
I thought I had this figured out but it turns out I'm just deleting
Alright, I thought I had this whole setTimeout thing perfect but I seem to
So, thought I had this working last night, couldve sworn it. Now it no
I thought I had resolved this but I obviously haven't and was hoping someone
I thought I had fixed this on Friday through a type correction, but I
I thought I had this all figured out, but now that I'm writing a
I had this working at one point, so I think I'm just referencing something

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.