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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:14:02+00:00 2026-05-29T22:14:02+00:00

I’m creating a database using entity framework code first and I’m having some issues

  • 0

I’m creating a database using entity framework code first and I’m having some issues with the database/POCO design. My problem is with inheritance.

My system has two main user roles Lecturer and Student. I have a base User class which contains Id, Logon, Role (identifying them as either lecturer or student), Forename and Surname. If the user is a Lecturer then they also have a Tags Property (relationship) associated with them. If the user is a Student then they have a year and a degree type property.

Both types of users can create projects. A project has a proposer. What i want is to be able to get the Lecturer or Student type back from Project.Proposer but i can’t seem to do that. I’m also not sure if Project.Proposer should be of type User (the base class) in the project class, whether i can use a interface (with code first) or what.

I would appreciate any guidance or ideas people could give me, I’ve tried many variations but none seem to give me the desired result. Note: I am trying to avoid having a user class that has redundant data so i don’t want the user class to contain the fields for lecturers and students.

  • 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-29T22:14:04+00:00Added an answer on May 29, 2026 at 10:14 pm

    The way todo this is properly in EF4 CodeFirst is to have a Proposer property of type User on the project.

    After retrieving the project the Proposer will have the correct type, but the value will be boxed as User. In order to figure out what actual the actual type is you can use the is keyword like this:

    // project is a Project instance    
    if (project.Proposer is Lecturer)
    {
       // do something
    } else if (project.Proposer is Student)
    {
       // do something else
    }
    

    This is the datastructure I would suggest:

    public class Tag
    {
        [Key]
        public int ID { get; set; }
    }
    
    public abstract class User 
    {
        [Key]
        public int ID { get; set; }
        public string Forename { get; set; }        
        public string Surename { get; set; }
    }
    
    public class Lecturer : User
    {
        public IEnumerable<Tag> Forename { get; set; }
    }
    
    
    public class Student : User
    {
        public IEnumerable<Tag> Forename { get; set; }
    }
    
    public class Project
    {
        [Key]
        public int ID { get; set; }
    
        public User Proposer { get; set; }
    }
    

    There are other ways to structure this, like introducing a hierachy for the projects by using classes like LecturerProject StudentProject and move the Proposer with the correct type into the those classes, but this is not recommended. Since you will always have to handle these project classes separately. For example when retrieving the name of the project and it’s proposer. Since the base project class does not have a proposer property anymore you need to have the same query twice. I hope I could illustrate the issues that arise when using this approach.


    The next question you need to ask yourself is, do you care how the data is saved in the db? SInce there are 3 ways of doing this for classes with inheritance:

    • Table per Hierarchy
    • Table per Type
    • Table per Concrete class

    One word of advice. If you are not planning on storing millions of records, don’t mind how it is actually stored in the db. Table per Hierarchy is by far the easiest to use, especially in the beginning, also it’s the default.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from

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.