A technique that maps an inheritance hierarchy of objects to a single table in relational database.
Questions tagged [table-per-hierarchy]
133 questions
12
votes
4 answers
Entity Framework one-to-many with table-per-hierarchy creates one foreign key column per subclass
I have a Garage which contains Cars and Motorcycles. Cars and motorcycles are Vehicles. Here they are:
public class Garage
{
public int Id { get; set; }
public virtual List Cars { get; set; }
public virtual List…

epalm
- 4,283
- 4
- 43
- 65
10
votes
1 answer
Entity Framework 4 Table Per Hierarchy - How To Define Navigational Properties On Children?
I currently have a Entity Framework 4.0 model in place with Table Per Type (TPT), but there are a few performance issues (lots of LOJ's/CASE statements), as well as an issue mapping between two particular domain areas (many-to-many).
I've decided to…

RPM1984
- 72,246
- 58
- 225
- 350
10
votes
3 answers
Entity Framework Multi-level Inheritance with TPH
I am working with a legacy system that implements a TPH for a certain number of items. So the current structure looks like this
Abstract Class 1 Abstract Class 2 Abstract Class 3
| | |
…

user3170736
- 511
- 5
- 24
10
votes
4 answers
Querying abstract models in dapper
I'm using Table Per Hierarchy database inheritance where columns for all derived types are in a single table. Each derived table is identified using a string Discriminator field that holds the name of the derived class:
---------------------
|…

ajbeaven
- 9,265
- 13
- 76
- 121
10
votes
1 answer
Entity Framework 6 & TPH inheritance: Map properties with the same name to same column by default
As of EF6 it is possible to do something like this when configuring Entity mappings using Table Per Hierarchy inheritance:
public class MyContext : DbContext
{
public DbSet Devices { get; set; }
protected override void…

joelmdev
- 11,083
- 10
- 65
- 89
9
votes
3 answers
Entity Framework 4 - Inheritance
I am trying to understand the inheritance mappings in EF4.
My database has two tables with the following structure:
PersonCategory Table:
CategoryID (int) (identity) (PK)
CategoryType (nvarchar(50))
Person Table
PersonID (int) (identity)…

muruge
- 4,083
- 3
- 38
- 45
6
votes
1 answer
Discriminator issue in inheritance mapping of Grails
I have 4 classes A, B, B1, B2 with inheritance mapping described as below:
A (mapped to table A) is the top-most parent class and its inheritance mapping strategy is tablePerHierarchy=false (means each of its sub-classes is mapped to a single…

Đinh Hồng Châu
- 5,300
- 15
- 53
- 90
5
votes
2 answers
Entity Framework 4.2 table per hierarchy group by discriminator
I am working on a project using an EF 4.2 code first model. This model contains a TPH inheritance structure for products. I need to group the polymorphic results of this inheritance model on the discriminator and am running into some issues.
The…

sgrade1979
- 51
- 3
5
votes
1 answer
Entity Framework table per hierarchy error 3034
I have an Entity Framework model using table per hierarchy. The base class is abstract and there are two derived classes.
I want to create associations between these two derived classes and another class. These are many-to-many relations so go…

user380689
- 1,766
- 4
- 26
- 39
5
votes
1 answer
Is it bad practice to use DiscriminatorFormula for migration of Hibernate databases?
I have an application using Hibernate for data persistence, with Spring on top (for good measure). Until recently, there was one persistent class in the application, A:
@Entity
public class A {
@Id
@Column(unique = true, nullable = false,…

Armand
- 23,463
- 20
- 90
- 119
5
votes
1 answer
Table-per-hierarchy and inheritance implementation issue
I am migrating an old ASP application to a modern .NET version, to cut down on development times we are looking at the .NET 4.0 Entity Framework. However, we seem to have hit a brick wall in our development with this issue.
Given is a small part of…

Bram Vandenbussche
- 1,401
- 11
- 22
5
votes
1 answer
Entity Framework Code First TPH inheritance - can different child classes share a field?
I have an Entity Framework Model created using Entity Framework Code First that is using Table Per Hierarchy inheritance where the structure looks a little like this:
public abstract class BaseState
{
public int Id { get; set; }
public…

glenatron
- 11,018
- 13
- 64
- 112
5
votes
0 answers
Entity Framework 5.0 inheritance with multiple assemblies
I'm using Entity Framework 5.0 with code-first approach plus inheritance for my business objects represented by Table Per Hierarchy.
I'd like to have the following structure:
//Assembly 'DataAccess'
public class MyDbContext : DbContext
{
…

Ben Sch
- 2,909
- 4
- 20
- 23
5
votes
1 answer
how to generate table per hierarchy using entity framework 5 model first
I'm using Visual Studio 2012 with entity Framework 5 model first.
I would like to generate my database using a table per hierarchy strategy, but can't find that option.
The Entity Designer Database Generation Power Pack is not available for visual…

Wim Simons
- 51
- 1
4
votes
0 answers
Fluent NHibernate automapping table-per-abstract-hierarchy / table-per-concrete-subclass
I have classes
public abstract class Content : IContent
{
public virtual Guid Id { get; protected set; }
public virtual IPage Parent { get; set; }
public virtual DateTime Created { get; set; }
/* ... */
}
public abstract class Page :…

Mike Koder
- 1,898
- 1
- 17
- 27