Questions tagged [tph]

TPH stands for Table Per Hierarchy which is a terminology that is used in Entity Framework as inheritance strategy to model the entities.

In the TPH mapping scenario, all types in an inheritance hierarchy are mapped to a single table. A discriminator column is used to identify the type of each row. When creating your model with Code First, TPH is the default strategy for the types that participate in the inheritance hierarchy. By default, the discriminator column is added to the table with the name “Discriminator” and the CLR type name of each type in the hierarchy is used for the discriminator values. You can modify the default behavior by using the fluent API.

Copied from: http://msdn.microsoft.com/en-us/data/jj591617.aspx#2.4

89 questions
1
vote
1 answer

Entity framework replaces delete+insert with an update. How to turn it off

I want to remove a row in database and insert it again with the same Id, It sounds ridiculous, but here is the scenario: The domain classes are as follows: public class SomeClass { public int SomeClassId { get; set; } public string Name {…
1
vote
1 answer

Query to Include Discriminator value when using TPH

When using TPH I have different types inheriting from a base. We have a search that queries across the abstract type. In the results, we want to show the type: ie. abstract Vehicle Car: Vehicle Truck: Vehicle in the results, I want to show 'type'…
Steve
  • 387
  • 4
  • 11
1
vote
0 answers

TPH Simple Config / Discriminator issue with subclasses

I am using Code first EF 6.1 with DotConnect for oracle data provider and TPH. I have created one class which has 2 subclasses. I am trying to add a record into existing database table. But it throws a DbUpdateException when I try to savechanges.…
user659469
  • 325
  • 1
  • 7
  • 22
1
vote
1 answer

TPH Discriminator not on base class / table

I'm having an issue with discriminators in TPH inheritance with Entity Framework v6.1.1 I would expect that the discriminator should fall on the table that is representative of the base class. However, it appears EF is trying to map the…
Nagoh
  • 813
  • 2
  • 10
  • 23
1
vote
1 answer

EF6 TPH mapping of derived property to specific table specific column

Have legacy DB with a Customer entity split in into 3 tables (1-1) with shared key. Wanted to use Code First TPH and map it to split tables. Here's simplified classes hierarchy (numerous primitive properties and their mappings omitted): public…
Paul Kyrejto
  • 1,285
  • 3
  • 12
  • 19
1
vote
0 answers

Entity Framework Mapping Foreign Key with Collections and TPH Inhehritance

I Try to map this simple model with TPH inheritance : public abstract class Master { public long Id { get; set; } public virtual ICollection Details { get; set; } } public class MasterA :…
1
vote
0 answers

How to connect TPH model to details page

I have a model as follows: public abstract class Product { public int ProductID { get; set; } public string ProductName { get; set; } } public class ProductA :Product { public string DetailA1 { get; set; } public string DetailA2 {…
OmerGokcek
  • 11
  • 1
0
votes
0 answers

TPT to TPH discriminator column issue

I had a class: public class A { } Now, I change it to abstract and create two implementations: public abstract class A { } public class First : A { } public class Second : A { } EF 6 completed the update and created the Discriminator column. But if…
0
votes
0 answers

Entity Framework invalid cast saving new tph record

Source code for this problem is on GitHub I have the following dbContext for a legacy data structure. [TypesInfoInitializer(typeof(OrgsContextInitializer))] public class OrgsEFCoreDbContext : DbContext { public…
Kirsten
  • 15,730
  • 41
  • 179
  • 318
0
votes
1 answer

How to combine ProjectTo with Map using Automapper?

To make it short here are database entities: public class Client { [Key] public int Id { get; set; } [Required] public string Name { get; set; } public ICollection Addresses { get; set; } } public abstract class…
0
votes
1 answer

TPH pattern in ef core for a shared table between different entities

i have a question. please suppose that we have different entities like category,blog,videos,... and each of them has own comments. how can i use one comment table for all of these entities just using one FK?is that TPH pattern?how can i implement it…
0
votes
0 answers

Configuring relationships between 2 TPH types using Fluent API

I have 2 abstract classes: Configuration and Room. Both of those have 2 concrete implementations for Coworking and Meeting (CoworkingRoomConfiguration, MeetingRoomConfiguration, MeetingRoom and CoworkingRoom). Both are configured to have a…
0
votes
0 answers

Invalid column name when using Entity Framework Core Table Per Hierarchy Inheritance

I am new to EF Core and am trying to use TPH Inheritance with Entity Framework Core I have the following classes defined public class WorkItem { public Guid Id { get; set; } public string WorkItemType { get; set; } public…
Chris
  • 1
  • 1
0
votes
1 answer

EF Core - ThenInclude() on collection with polymorphic elements

I am trying to eager load properties from elements of a collection which itself is a property of another class. The elements of the collection are polymorphic, not sharing the properties I am trying to include, and tracked in the DB via TPH…
be_cracked
  • 91
  • 2
  • 11
0
votes
0 answers

How to read TPH type from a sproc in EF6?

ObjectContext.Translate doesn't handle TPH types for T. Is there way to read TPH types from a sproc easily in EF6? Assume the entire table record (along with the discriminator column) is read, with something like "select *" for maintainability…
Triynko
  • 18,766
  • 21
  • 107
  • 173