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

The Archive Base Latest Questions

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

I am an experienced .NET developer but new to EF – so please bear

  • 0

I am an experienced .NET developer but new to EF – so please bear with me. I will use an example of a college application to illustrate my problem. I have these user roles:

Lecturer, Student, Administrator.

In my code I envisage working with these entities as distinct classes so e.g. a Lecturer teaches a collection of Students. And work with ‘is Student’ ‘TypeOf’ etc.

Each of these entities share lots of common properties/methods e.g. they can all log onto the system and do stuff related to their role.

In EF designer I can create a base entity Person (or User…) and have Lecturer, Student and Administrator all inherit from that.

The difficulty I have is that a Lecturer can be an Administrator – and in fact on occasion a Student can be a Lecturer.

If I were to add other entities such as Employee and Warden then this gets even more of an issue.

I could presumably work with Interfaces so a person could implement ILecturer and IStudent, however I do not see how this fits within EF.

I would like to work within the EF designer if possible and I’m working model-first (coding in C#).

So any help and advice/samples would be very welcome and much appreciated.

Thanks

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

    Don’t make Student and Lecturer inherit from Person. As you say, what if “Bob” was both a student and a lecturer? This happens all the time in real colleges. You said it best yourself: These are roles, not types. A person can have many roles.

    As a rule of thumb, avoid inheritance in O/R mapping when it’s not strictly necessary (which is almost never). Just as when coding, favor composition over inheritance.

    So you could give each Person a property Roles which is a 0..* collection of Roles. Then to get a list of students, you can do:

    var students = from p in Context.People
                   where p.Roles.Any(r => r.Id = studentRoleId)
                   select p;
    

    Or you could have a related Student type with a 0..1 relationship between Person and Student; this would allow you to add additional data for the student, e.g.:

    var students = from p in Context.People
                   where p.StudentInfo != null
                   select new
                   {
                       Id = p.Id,
                       Name = p.Name,
                       Grades = p.Student.Grades
                   };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.