A technique that maps an inheritance hierarchy of objects to a single table in relational database.
Questions tagged [table-per-hierarchy]
133 questions
4
votes
0 answers
How to write select query with EF-TPH class
Work on EF-6 mvc5 project.Face problem with table per hierarchy classs.My class structure is bellow.
Above picture describes in detial class relations.
Want to write a select query which can select my home,room and there related devices with device…

shamim
- 6,640
- 20
- 85
- 151
4
votes
1 answer
EF6 - TPH foreign key mapping in derived classes using base class property
I am using Entity Framework 6.0.2 with an existing database in which tags are stored in a single table that looks like this:
Id: int, primary key
TagType: string, determine the type of tag, either "usertag" or "movietag"
ItemId: int, contains…

Erik Schierboom
- 16,301
- 10
- 64
- 81
4
votes
1 answer
Entity Framework Code First - select based on type of child TPH class
I am currently working with Entity Framework 4 on a project that is using Table Per Hierarchy to represent one set of classes using a single table. The way this works is that this table represents states and different states are associated with…

glenatron
- 11,018
- 13
- 64
- 112
3
votes
2 answers
DiscriminatorFormula
If I have a single table where I need multiple columns for discriminator, is my only solution to use a @DiscriminatorFormula?
I ask because some prototyping gave us some results that I cannot explain.
Failed Prototype: Initially we prototyped a…

John Duff
- 157
- 1
- 3
- 9
3
votes
0 answers
I am looking for a central action solution for tph tables
Net core project, I'm writing a ticket management service.
I applied the TPH(Table Per Hierarchy) method in the database.
I created a table called TicketGeneral as a main table.
The names of the sub-entities are as…

Rippez
- 41
- 2
3
votes
1 answer
EF: Can I mix TPH and TPT when abstract base and a few concrete types are in TPH-table and other types have their own table?
First of all, these questions are similar but definitely not the same:
Can I mix Table per Hierarchy and Table per Type in Entity Framework? - Refers to a different scenario.
Entity Framework: mix table per type and table per hierarchy - Yet another…

Danny Varod
- 17,324
- 5
- 69
- 111
3
votes
1 answer
EF4.1 Exception creating Database with table-per-hierarchy inheritance
I have created a very simple project to demonstrate table-per-hierarchy inhertiance. In my unit test which tries to generate the database, i get one of a number of errors depending on the config:
without the Required() method
Map(x =>…

jenson-button-event
- 18,101
- 11
- 89
- 155
3
votes
2 answers
Entity Framework - Discriminate on multiple values
In a Table-Per-Hierachy scenario is it possible to discriminate on a list of possible values?
e.g. for the types Color, DarkColor, LightColor
something like
Map(m => m.Requires("TheColor").HasValue(Red || Blue)
Map(m =>…

jenson-button-event
- 18,101
- 11
- 89
- 155
3
votes
1 answer
Entity Framework TPH on top of TPT
This problem will be explained around 3 classes: Account, IndividualAccount, and Doctor:
First two classes are abstract
IndividualAccount is Account's subclass
Doctor is IndividualAccount's subclass
The first layer of inheritance (between…

mdoust
- 429
- 1
- 4
- 20
3
votes
2 answers
Table-per-hierarchy and composite primary key
I have two tables in a legacy database (which I cannot modify) with data as follows:
Table1 has a composite primary key (Code, Abbrev), but Abbrev is also used as a discriminator (see below). Table2 has two foreign key columns (CodeA, CodeB), both…

Tomaz Tekavec
- 764
- 6
- 22
3
votes
1 answer
How to automatically create concrete classes based on field value
Consider this example:
Database (similar to Stackoverflow) has a table with questions and answers in the same table distinguishable by PostType field. I would like to get back a list of lastest posts be it questions or answers.
As questions and…

Robert Koritnik
- 103,639
- 52
- 277
- 404
3
votes
1 answer
Smartest approach to changing from one subclass to another (updating the discriminator value)
Background: I'm implementing persistence for the following classes:
class Person
abstract class ContactInfo
Email extends ContactInfo
SnailMail extends ContactInfo
Each Person has a reference to a ContactInfo object. (And a ContactInfo object…

aioobe
- 413,195
- 112
- 811
- 826
2
votes
1 answer
TPH vs TPT vs TPC and OR mappers
I'm working on a datamodel that has a set of types that share some common fields such as Id, Name, Description. To be more concrete:
The Document class has a list of Attributes. These Attributes are in our domain, types like String, Integer,…

OKB
- 715
- 3
- 14
- 30
2
votes
0 answers
Both Table-Per-Hierarchy and Table-Per-Type in Entity Framework Core
Please, note the question is about EF Core and not EF4 or EF6.
I have this structure:
public abstract class Account {}
public class Customer : Account {}
public abstract class Supplier : Account {}
public class Company : Supplier {}
public class…

Simone
- 2,304
- 6
- 30
- 79
2
votes
1 answer
Many-to-many with TPH inheritance in EF Core
I am having trouble with setting up a many-to-many join table with EF core if one side of the join table is a derived class in table-per-hierarchy set up.
Here's the set up:
class Chore
{
Guid Id;
}
class LaundryChore : Chore
{
//…

Soojin J
- 23
- 2