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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:45:40+00:00 2026-06-08T04:45:40+00:00

I have to create an entity framework model for a badly designed database. The

  • 0

I have to create an entity framework model for a badly designed database. The database uses table per type inheritance but it does so with using a PK->FK relationship, not a PK->PK relationship. E.g.

Person
   PersonID (PK)
   Name

Employee
   EmployeeID (PK)
   PersonID (FK)
   DateStarted

HourlyEmployee
   HourlyEmployeeID (PK)
   EmployeeID (FK)
   HourlyRate

Obviously this is just badly designed, but I can’t change it. Table per type inheritance in the entity framework essentially wants EmployeeID not to exist and the PK for Employee to be PersonID. Is it possible to create a model for this database, or do I choose another tool? any recommendations?

  • 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-06-08T04:45:42+00:00Added an answer on June 8, 2026 at 4:45 am

    You will not map this as TPT inheritance because your database is configured in the way that doesn’t allow you cheating EF.

    If Employee.EmployeeID is auto-generated in the database and Employee.PersonID is unique (uniqueness must be enforced in the database) you should be able (not tested) to cheat EF by simply mapping:

    public Employee : Person {
        public DateTime DateStarted { get; set; }
    }
    

    This class will tell EF that Employee inherits key from Person (PersonID) and you will hide the real key from EF – this should work if the real key is auto-generated.

    The problem is your next level of inheritance which breaks this pattern. To make this work your HourlyEmployee will have to reference PersonID – not EmployeeID. EF now doesn’t know about EmployeeID existence so it even cannot map relation with HourlyEmployee.

    TPT inheritance in code first has one additional limitation – PK column must have the same name in all tables.

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

Sidebar

Related Questions

I have 4 tables: but when I create an entity framework model, why is
I am using Entity Framework Code First to create a database table. My model
I have an Entity Framework 4 model-first design. I create a first draft of
Application uses Entity Framework 4.1 with database first approach. I have in database a
I use Entity framework for creating model. I have table hierarchy where User is
I have a Entity Framework model class that has a view to create an
I have created a Dynamic Data site against an Entity Framework Model I have
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I have created an entity data model and generated a database from it. One
I am trying to create an Entity Framework 4 model based on a legacy

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.