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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:15:33+00:00 2026-05-23T15:15:33+00:00

I have a class that inherits a base class to which another class has

  • 0

I have a class that inherits a base class to which another class has relationships.

Example:

  • Base class: Animal
  • Subclass 1: Dog
  • Subclass 2: Cat
  • Related one-to-many table: Vaccinations
    • A dog can have multiple vaccinations. This is implemented as a List<Vaccination>.
    • A cat can have multiple vaccinations.
    • A vaccination record can only have one animal associated with it.
    • A vaccination doesn’t know if it’s associated with a dog or a cat. (Dogs and cats use non-colliding GUIDs.)

There is no Animal table; Animal is an abstract class. But Vaccination knows only about Animal, not about Dog. (EF, however, knows about both.) I have my class libraries split such that Animal and Vaccination are in a core library and Dog is in another library that references the core library.

When using Entity Framework Code First, the Vaccinations table is getting the extra column: Dog_ID, as Dog class’s List<Vaccination> explicit declaration is creating an inference. As such, this column maps the vaccination record to the dog. This would be fine, except for the fact that I want to share this extra column across multiple types of Animal. So for example rather than have a Dog_ID and a Cat_ID I’d like to have an Animal_ID that could join to either the Dog or the Cat.

As Animal is abstract and has no DB table, can I accomplish this with perhaps a fluent statement and/or property/attribute declarations?

  • 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-23T15:15:33+00:00Added an answer on May 23, 2026 at 3:15 pm

    Your Vaccination table will always have additional FK column for each vaccinated type of animals unless you create Animal table and make relation to that table. EF cannot map and high level abstraction of relations – relations must follow same rules as if you create them directly in the database.

    If only some animals can be vaccinated you can add another table to hierarchy and make relation with that new table (EF is not able to work with interfaces). You will need Table per Type mapping for that and it will make performance of your queries much worse in current EF version.

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

Sidebar

Related Questions

I have a class (Descendant1) that inherits from a base class (BaseClass). An instance
I have a class A and another class that inherits from it, B. I
I have a class Application that my global.asax inherits from. The class has this
I have a class that inherits from a base class. This base class exposes
I have a parent class in rails that inherits from ActiveRecord::Base. I'm trying to
I have a class that inherits a generic dictionary and an inteface public class
I have a class that inherits from ObservableCollection(Of MyObject) and the MyObject class handles
if i have a .net 1.1 class that inherits from DictionaryBase and i am
I have a standard windows server that inherits from the ServiceBase class. On the
I have a class that I want to use to store properties for another

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.