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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:14:23+00:00 2026-05-21T03:14:23+00:00

and thanks in advance for your time. We are using CSLA 3.5.1, although, ultimately,

  • 0

and thanks in advance for your time.

We are using CSLA 3.5.1, although, ultimately, this problem may not have much to do with CSLA.

My company has gone a long way down the road of a common modeling error and is finally having to face it. I’ve simplified the domain objects below to clarify the problem:

We have 3 classes defined as such:

class Person : BusinessBase

class Student : Person

class Teacher : Person

We are using NHibernate for our ORM, and the Student and Teacher classes are joined subclasses of Person in our mappings (we have Person, Student, and Teacher tables), using the PersonID as a derived key.

The problem, as you may have anticipated, is now we have a situation where a Student can also be a Teacher. Under the current object and data models, this causes a primary key violation when we try to add a Student that is already a Teacher or vice-versa.

Question One: Is there any CSLA magic I can perform on the business object before saving the new record to prevent this situation?

If not…

In researching this problem, I’ve seen two suggestions to solve it, The first is to favor composition over inheritance. To my understanding, this means Student and Teacher would each contain a Person property.

Question Two: In order to get this to work, is it correct to assume the Student and Teacher tables would need a foreign key into the Person table? I guess I don’t have a complete understanding of this solution, and would like some guidance.

The second solution involves thinking of Student and Teacher as Roles a given person plays. From what I’ve seen, the Person class would need a Roles collection, and link table (PersonRoles?) is used to map the records in the Student and Teacher tables to the Person.

Question(s) Three: What do the Role base class and the PersonRoles table look like? I believe the Student and Teacher subclasses would just contain their appropriate properties. Is this correct?

Any opinions on a solution? If anyone can find a fleshed-out example on the web, I’d love to see it.

Thanks,

Will.

  • 1 1 Answer
  • 1 View
  • 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-21T03:14:24+00:00Added an answer on May 21, 2026 at 3:14 am

    Question 1: Not to my knowledge. That’s not saying much; I haven’t used CSLA, but my thoughts are that this is an NHibernate thing, and has to be solved with NHibernate.

    Question 2: Yes, conceptually. A Person has zero to one Students and zero to one Teachers, but all Students and Teachers require a Person reference. I use Fluent NHibernate for this, so you’ll have to look up the equivalent HBM syntax, but:

    public class PersonMap:ClassMap<Person>
    {
        public PersonMap()
        {
            Table("Person");
            Id(x=>Id).Column("PersonID");
            References(x=>x.Student).KeyColumn("StudentID")
                Nullable().Cascade.All();
            References(x=>x.Teacher).KeyColumn("TeacherID")
                Nullable.Cascade.All();
        }
    }
    
    
    public class TeacherMap:ClassMap<Teacher>
    {
        public TeacherMap()
        {
            Table("Teacher");
            Id(x=>Id).Column("TeacherID");
            References(x=>x.Person).KeyColumn("PersonID")
                .Not.Nullable().Cascade.None();        
        }
    }
    
    public class StudentMap:ClassMap<Student>
    {
        public StudentMap()
        {
            Table("Student");
            Id(x=>Id).Column("StudentID");
            References(x=>x.Person).KeyColumn("PersonID")
                .Not.Nullable().Cascade.None();        
        }
    }
    

    Now, Person is the apex of this object graph; you may retrieve People, Students or Teachers, but when saving changes, always save the Person, and the child roles of that Person will also be persisted.

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

Sidebar

Related Questions

First time using wordpress query so not sure how to handle this problem. I
and thanks in advance for offering your time for reading this. I am newbie
Thanks in advance for your time and assistance. I am using Azure Client Library
Thanks in advance for your help. I have a need within an application to
Thanks in advance for your assistance. I have the following exported part: [Export (typeof(INewComponent))]
First off, thanks in advance for your help. This issue is driving me nuts.
Thanks in advance for taking the time to read my question. I'm using MySQL
and thanks in advance for your help! Here's my situation: I have a set
Hi there and thanks for taking the time for this question. I'm using a
Thanks in advance for your help experts. I want to be able to copy

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.