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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:28:56+00:00 2026-05-31T03:28:56+00:00

Having difficulty finding relevant search results… Given this model: public abstract class A {

  • 0

Having difficulty finding relevant search results…

Given this model:

public abstract class A
{
    public int ID { get; set; }
    public int CustomerID { get; set; }
    public virtual Customer Customer { get; set; }
}

public class B : A
{
}

public class C : A
{
}

public class Customer
{
    public int ID { get; set; }
    public virtual ICollection<B> Bs { get; set; }
    public virtual ICollection<C> Cs { get; set; }
}

With this configuration:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<A>().ToTable("As");
    modelBuilder.Entity<B>().ToTable("Bs");
    modelBuilder.Entity<C>().ToTable("Cs");

    base.OnModelCreating(modelBuilder);
}

I get this result in the DB:

Database

Question:

Is inheritance of navigation properties not supported? If I add public string SomeSharedProperty { get; set; } to A then as I would expect the column for that property only showed up in the As table.

What reason is there for the Customer_ID column in the Bs and Cs table? Is there any way to tell EF to not map that inherited property?

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-31T03:28:57+00:00Added an answer on May 31, 2026 at 3:28 am

    First off, inheritance is supported. But it seems in this specific instance not as you would expect.

    Since Relational DBs do not support inheritance as we know it from object oriented programming there has to be some kind of transformation in order to make it happen.

    Here is a series of blog post covering the issue in detail:

    • Table per hierarchy
    • Table per type
    • Table per class

    It also tries to give guidelines when to use which of the strategies.

    UPDATE
    Apparently this is more tricky than it seemed at first glance. What you see is most likely due to a circular reference: A -> B -> Customer -> Bs.

    The CustomerID columns of Bs/Cs are NOT the inherited ones from the As Table. It is in fact the representation of the relation properties specified on the Customer class:

    public virtual ICollection<B> Bs { get; set; }
    

    results in a nullable CustomerID column on table B.

    public virtual ICollection<C> Cs { get; set; }
    

    results in a nullable CustomerID column on table C.

    So those nullable columns are used to represent the relation Customer -> Bs and Customer -> Cs. Their appearance has nothing to do with the Customer property on the A class.

    You can easily check this by removing the navigation properties of the customer class. Then the result is what you would expect: A CustomerID column on the A table and no CustomerID column on B / C Table.

    So in order to solve this you need to specifically tell EF how to resolve the circular reference. Not sure this is possible though, I’m afraid you will need to omit the Bs/Cs properties on the Customer and write a LINQ query instead to retrieve the info.

    If you need those properties on the Customer class you can do is something like this:

    public class Customer
    {
        public int ID { get; set; }
    
        // this is necessary to have access to the related Bs/Cs
        // also it cant be private otherwise EF will not overload it properly
        public virtual ICollection<A> As { get; set; }
    
        public IEnumerable<B> Bs { get { return this.As.OfType<B>(); } }
        public IEnumerable<C> Cs { get { return this.As.OfType<C>(); } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to crowd-source this, as I'm having bit of difficulty finding an industry
I'm having difficulty finding support on this topic, because I know how to pass
I am having difficulty finding space and time complexity for this code that i
This is probably an extremely basic question but I'm having difficulty finding an answer.
There is probably a really straightforward answer to this but I'm having difficulty finding
I'm currently having difficulty finding a way of making my loops work. I have
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I'm having difficulty searching for this. How would I define an element in an
I am working on creating a python c extension but am having difficulty finding
Im having difficulty finding an algorithm for the following puzzle- A string is called

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.