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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:41:56+00:00 2026-05-23T13:41:56+00:00

I have 3 tables in my SQL Server database: Teacher Student Parent Each of

  • 0

I have 3 tables in my SQL Server database:

  • Teacher
  • Student
  • Parent

Each of these tables contains some columns which are also found in the others, for example:

  • FirstName
  • Surname

All the other columns are different. This is a legacy database. I can’t change it.

In my C# code, I would like to have:

public partial class Person
{
    public string FirstName { get; set; }
    public string Surname { get; set; }

    public virtual ICollection<Role> Roles { get; set; }
}

public interface Role
{
}

public partial class Teacher : Role
{   
    public string School { get; set; }
}

public partial class Student : Role
{
    public string YearLevel { get; set; }
}

public partial class Parent : Role
{
    public string Blagh { get; set; }
}

That is, a polymorphic many-to-one association between Role and Person.

The reason I want this is because a person can be both a teacher and a parent.

My question is, what technology should I use to populate the business objects from the database?

I’ve looked at Entity Framework 4.1 DbContext stuff; I like the data annotation approach, but can it do what I want? If not, can the Fluent API?

If the Entity Framework can’t do this, then how about NHibernate (preferably using attributes), or Linq-to-SQL?

I know NHibernate can handle a polymorphic association, but can this be done where we are splitting the tables between entities like here?

  • 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-23T13:41:57+00:00Added an answer on May 23, 2026 at 1:41 pm

    The closest you can get with Entity framework is TPC inheritance:

    public abstract class Person
    {
        public string FirstName { get; set; }
        public string Surname { get; set; }
    }
    
    public partial class Teacher : Person
    {   
        public string School { get; set; }
    }
    
    public partial class Student : Person
    {
        public string YearLevel { get; set; }
    }
    
    public partial class Parent : Person
    {
        public string Blagh { get; set; }
    }
    

    Nothing more because:

    • EF is not able to map multiple entities to the same table without inheritance or table splitting
    • EF is not able to map multiple relations to single navigation property
    • Teacher and Parent will always be two different not related persons.

    I doubt that NHibernate supports this because what you shown is not pure polymorphic association (there is still problem with non deterministic mapping of Person) but perhaps somebody will surprise me.

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

Sidebar

Related Questions

In a SQL server database, I have a table which contains a TEXT field
I have a SQL Server 2000 database with around a couple of hundred tables.
I have designed database tables (normalised, on an MS SQL server) and created a
We have two tables in a SQL Server 2005 database, A and B.There is
I have two tables in a SQL Server 2008 database in my company. The
I have developed a Windows application in .NET which uses a SQL Server database
In our SQL Server Database we have at least 25-35 lookup / empty tables
I have MS SQL Server database and insert some values to one of the
I have a table in a SQL Server 2005 database with a trigger that
Lets say I have a table in a sql server 2000 database called TransactionType:

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.