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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:17:54+00:00 2026-06-16T00:17:54+00:00

I am having an issue with how the database is being generated for an

  • 0

I am having an issue with how the database is being generated for an inheritance relationship in my entity classes. It is correctly making the primary key ID in the subclass table reference the ID in the superclass table – but it is also creating a foreign key in the superclass table which it doesn’t need. Here are my classes:

Abstract superclass:

public abstract class DaqObject
{
    public int ID { get; set; }
    public int AgencyID { get; set; }
    public int DaqObjectTypeID { get; set; }

    [ForeignKey("AgencyID")]
    public virtual Agency Agency { get; set; }
    [ForeignKey("DaqObjectTypeID")]
    public virtual DaqObjectType DaqObjectType { get; set; }

    public virtual Document InheritingDocument { get; set; }
}

The corresponding database table has the following columns:

  • ID (PK, int, not null)
  • AgencyID (FK, int, not null)
  • DaqObjectTypeID (FK, int, not null)
  • InheritingWell_ID (FK, int, null)

Subclass:

public class Document : DaqObject
{
    public string Name { get; set; }
}

With a corresponding database table with the following columns:

  • ID (PK, FK, int, not null)
  • Name (nvarchar(max), null)

(These classes have been slimmed down for the example.)

The DaqObject table in the database ends up with an InheritingDocument_ID column. I can create the database myself and make the relationship without that foreign key in the superclass table. Is it possible to have EF code first do the same?

  • 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-16T00:17:54+00:00Added an answer on June 16, 2026 at 12:17 am

    The InheritingDocument in the DaqObject tells EF to create one:many relationship between Document and DaqObject entities. That’s why there is the InheritingDocument_ID column in your DB.

    I suppose, it isn’t what you want, you have added the InheritingDocument property to make inheritance work, right? It isn’t necessary, EF will take care of inheritance handling automatically. There is a nice blog post, that describes possible strategies for working with inherited classes with the EF.

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

Sidebar

Related Questions

Running KODO 4.2 and having an issue inefficient queries being generated by KODO. This
I'm having a bit of an issue uploading files to a database. The table
I am having an issue logging into a SQL Server 2000 Database via Windows
I'm having an issue with inserting JSON into a database, my intention is to
I'm having a bit of an issue uploading files to a database. I'll post
I'm having an issue with storing sessions in a MySQL database using CGI::Session. Here
I generated a database through entity framework. Here is the connection string: <add name=AnnouncementsContainer
I am having a weird issue in ASP.NET MVC with objects not being updated
I'm having an issue updating an entity with multiple related entities. I've got a
I'm having an issue in where records occasionally go missing from our production database.

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.