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

The Archive Base Latest Questions

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

Taking an example that is provided on the Fluent nHibernate website, I need to

  • 0

Taking an example that is provided on the Fluent nHibernate website, I need to extend it slightly:

alt text
(source: fluentnhibernate.org)

I need to add a ‘Quantity’ column to the StoreProduct table. How would I map this using nHibernate?

An example mapping is provided for the given scenario above, but I’m not sure how I would get the Quantity column to map to a property on the Product class:

public class StoreMap : ClassMap<Store>
{
  public StoreMap()
  {
    Id(x => x.Id);
    Map(x => x.Name);
    HasMany(x => x.Employee)
      .Inverse()
      .Cascade.All();
    HasManyToMany(x => x.Products)
     .Cascade.All()
     .Table("StoreProduct");
  }
}
  • 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-15T07:35:00+00:00Added an answer on May 15, 2026 at 7:35 am

    One suggestion would be to not use the hasManyToMany mapping and have a separate mapping class for StoreProduct which is a subclass of Product.

    New Store Mapping

    public class StoreMap : ClassMap<Store>
    {
      public StoreMap()
      {
        Id(x => x.Id);
        Map(x => x.Name);
        HasMany(x => x.Employee)
          .Inverse()
          .Cascade.All();
        HasMany(x => x.Products)
         .Cascade.All();
      }
    }
    

    NB changed HasManyToMany to HasMany instead.

    New sub class mapping for Store Product

    public class StoreProductMap : SubclassMap<StoreProduct>
    {
       References(x=>x.Store);
    
       Map(x=>x.Quantity);
    }
    

    New StoreProduct entity

    public class StoreProduct : Product
    {
        public virtual Store Store {get;set;}
        public virtual int Quantity {get;set;}
    }
    

    Hope that helps.

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

Sidebar

Related Questions

In a CS course I'm taking there is an example of a language that
I start to use Java annotations heavily. One example is taking method with annotations
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
Is there a way for taking type of a template class, for example //i
Taking over some code from my predecessor and I found a query that uses
Taking shs's question a step further... Why isn't all government sponsored software open source?
Is there any chance that I could use Lucene's ShingleAnalyzerWrapper to generate bigrams taking
Taking e.g. Python as a good example of a modern scripting language, it has
Taking photos using system provided component(MediaStore.ACTION_IMAGE_CAPTURE) is quit common. As I ve experimented, with

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.