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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:06:39+00:00 2026-06-13T03:06:39+00:00

We have an entity like Vehicle and three derived entities such as Car ,

  • 0

We have an entity like Vehicle and three derived entities such as Car, Motorbike and Bicycle.
This inheritance hierarchy is implemented with TPH.

Here are entity mapping conditions:

  • __disc__ = car for Car
  • __disc__ = motorbike for Motorbike
  • __disc__ = bicycle for Bicycle

    How can I derive another child from Vehicle like MotorVehicle with following mapping condition:

  • __disc__ = car OR motorbike for MotorVehicle

I’d view in Database like this when I had this structure with TPT:

SELECT    Id
FROM      Vehicles
WHERE     (__Disc__ = N'car') OR (__Disc__ = N'motorbike')

I think this view is not required with TPH.

Please note that I can not change the inheritance like this: Vehicle<– MotorVehicle<– Car. Don’t think about injecting the motor vehicles as the parent of car and other children because Car and Motorbike and Bicycle are already exists. I just want to assign some business to all motor vehicles.

  • 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-13T03:06:40+00:00Added an answer on June 13, 2026 at 3:06 am

    Why couldn’t you introduce a MotorVehicle level in the class hierarchy? You can. It’s just an abstract class, so it doesn’t need a discriminator value. EF hardly notices the class!

    I tried both with and without the MotorVehicle class and the database structure and the number of defined discriminators was the same in both cases.


    Edit

    This is what I did:

    public abstract class Vehicle
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    
    public abstract class MotorVehicle : Vehicle
    {
        public int Hp { get; set; }
    }
    
    public class Car : MotorVehicle
    { }
    
    public class MotorBike : MotorVehicle
    { }
    
    public class Bicycle : Vehicle
    { }
    
    internal class NestedInheritanceContext : DbContext
    {
        public DbSet<Vehicle> Vehicles { get; set; }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Vehicle>().Property(v => v.Name).IsRequired();
            modelBuilder.Entity<Car>().Map(m => m.Requires("Discriminator")
                .HasValue("car").HasColumnType("char")
                .HasMaxLength(10)
                .IsRequired());
            modelBuilder.Entity<MotorBike>().Map(m => m.Requires("Discriminator")
                .HasValue("motorbike"));
            modelBuilder.Entity<Bicycle>().Map(m => m.Requires("Discriminator")
                .HasValue("bicycle"));
            base.OnModelCreating(modelBuilder);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a Student entity like this implemented using the Play Framework's
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have an entity which looks like this: Entityname = Country with the attributes
I have an entity which looks something like this: (I'm coding to the web
I have an Entity in Code First Entity framework that currently looks like this:
I have a Customer class defined like this: @Entity public class Customer { //...
I have a Person and an Organisation Entity: Person looks like this: public class
I have a JPA object which has a many-to-many relationship like this: @Entity public
I have two tables associated by FK. Table student is mapped like this: @Entity
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need

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.