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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:18:41+00:00 2026-05-11T14:18:41+00:00

I have a model where multiple classes have a list of value types: class

  • 0

I have a model where multiple classes have a list of value types:

class Foo { public List<ValType> Vals; } class Bar { public List<ValType> Vals; } 

Foo and Bar are unrelated apart from that they both contain these vals. The rules for adding, removing, etc. the ValTypes are different for each class. I’d like to keep this design in my code.

There are times when I want to copy some Vals from a Foo to a Bar, for example. In the database, each ValType has its own table, to keep it small, light (it just has the parent ID + 2 fields), and allow integrity checks. I know NHibernate says I should keep my objects as granular as the database, but that just makes my code uglier.

The best I’ve thought of so far is to make separate subclasses of ValType, one for each parent. Then I can map those at that level. Then, I’ll hook up add and remove logic to auto-convert between the right subclasses, and actually store them in a private list that has the right subclass type. But this seemed a bit convoluted.

How can I map this in NHibernate (Fluent NHibernate if possible)?

Please let me know if this is a duplicate — I’m not quite sure how to search this.

  • 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. 2026-05-11T14:18:41+00:00Added an answer on May 11, 2026 at 2:18 pm

    You can find an example on the Google Code page for Fluent NHibernate.

    Model

    public class Customer {     public string Name { get; set; }     public string Address { get; set; } } 

    Schema

    table Customer (     Id int primary key     Name varchar(100) )  table CustomerAddress (     CustomerID int,     Address varchar(100) ) 

    Mapping

    public class CustomerMap : ClassMap<Customer> {     public CustomerMap()     {         Id(x => x.Id);         Map(x => x.Name);          WithTable('CustomerAddress', m =>         {             m.Map(x => x.Address);         });     } } 

    In this example, an entity is split across two tables in the database. These tables are joined by a one-to-one on their keys. Using the WithTable feature, you can tell NHibernate to treat these two tables as one entity.

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

Sidebar

Ask A Question

Stats

  • Questions 159k
  • Answers 159k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Solution A is better. Anytime you try to store collections… May 12, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer As Louis states, XCode doesn't currently provide a publicly accessible… May 12, 2026 at 11:31 am
  • Editorial Team
    Editorial Team added an answer Having had no tidbits submitted on this I delved further… May 12, 2026 at 11:31 am

Related Questions

I've got a WPF application where PageItems are model objects. My main ViewModel has
Basically, I have a model where I've created a superclass that many other classes
This question is related to (but perhaps not quite the same as): Does Django
I have two models, Room and Image . Image is a generic model that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.