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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:01+00:00 2026-06-17T21:55:01+00:00

I have couple of classes which inherits 1 base abstract class. It is mapped

  • 0

I have couple of classes which inherits 1 base abstract class. It is mapped via fluent API to existing database (using Table-Per-Concrete-Type, i.e. base abstract class not mapped to any table).

Now I want to add some statistics to my code and the best solution for me is to use TPH approach for 3-4 new classes. It maybe or maybe not inherits the same class as described above.

But I do not know how to instruct EF use TPH-approach for these 3-4 classes. Am I need to add correect table with discriminators and it will be used ok? Or I need to specify it somehow via fluent API?

  • 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-17T21:55:03+00:00Added an answer on June 17, 2026 at 9:55 pm

    I found. You do not need to specify somehow EF that you want to use TPH. Enough to do following:

    Create classes hierarchy

    class Base { ... }
    class Derived1 : Base { ... }
    class Derived2 : Base { ... }
    .......
    class DerivedN : Base { ... }
    

    Create table called as your base type (otherwise do not forget to map it using ModelBuilder) with common columns (content of Base) and with one column per public property in each derived types. Add “Discriminator” column (nvarchar(128), but I suggest to use varchar unless you using unicode classes names).

    In your successor of DbContext add only one DbSet: DbSet<Base> Data { get; set; } and use it for CRUD operations.

    That is all!

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

Sidebar

Related Questions

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I have a couple of classes that share a common base class, with the
I have a couple classes that can each have comments: class Movie < ActiveRecord::Base
I have a structure of base class and a couple of inherited classed. Base
I have this simple application with a couple of classes which are all related.
I have a couple Java classes which have blackbox test cases that just exercise
I have a couple of classes which functions are execute SQL statements against a
I have a couple of classes one of which keeps reference to the object
I have created a couple custom classes ( NTDropDown and NTBaseFreight ) which I
When starting my application, I have a couple of classes which are required to

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.