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
0
votes
0 answers

EF Core TPH Migration - Derived types have no key defined

EF migrations fails and tells me that the derived types have no key defined. I'm trying to setup TPH, which should be fairly easy with attributes, but I can't get it to work with separate (fluent-)configuration files. It always reports that the key…
0
votes
0 answers

How to map object of one class to another class with EF code first TPH

Scenario I have e.g. abstract class called Quiz and two children of this Quiz: SingleAnswerQuiz and MultipleAnswerQuiz. I map this model into Table per hierarchy with entity framework. Problem Is there any way to change one SingleAnswerQuiz type to…
zolty13
  • 1,943
  • 3
  • 17
  • 34
0
votes
0 answers

Adding Entity Framework core code first sublass with existing property name

What is best/a good practise in the following situation when using TPH inheritance in Entity Framework?: I have abstract class Base { ... } class Sub1 { public int Amount {get;set;} } and a DbContext with: protected override void…
lappy4711
  • 1
  • 1
  • 2
0
votes
1 answer

EF6 Use Existing Db Column as Discriminator

I am using Entity Framework 6 Code First for my project. Entities have Inheritance so I am following TPH(Table per Hierarchy). I read following Article and many others. None of them explain a way in which I can use an existing DB Column mapped to a…
Alok
  • 46
  • 4
0
votes
1 answer

Entity Framework 6 Table Per Hierarchy specific includes

I have a problem with EF6 when I do a Table per Hierarchy mapping. I have an Person class that has Employee and Manager children. The two classes are nearly the same, except for one field: DepartmentId (and the subsequent linked component…
0
votes
0 answers

How to block creation redundant FK Constraint in EF TPH Code First

I use in some project EF code First with TPH (in part of classes) I have class like this: namespace Billing.Model.Domain.Entities.BilProject { [Table("ProjectPriceList")] public abstract class ProjectPriceList { [Key,…
mangood
  • 67
  • 7
0
votes
1 answer

EF4 CTP5 How To? Map an inherited Property to a field in a related table

i defined an entity called Variable and derived classes by using Table Per Hierarchy (TPH). The Base class "Variable" contains a collection of PropertyValues: private ICollection propertyValues; public const string…
The Chris
  • 591
  • 6
  • 19
0
votes
1 answer

Load explicit entity (not entities extending it) with EF

We've got a code first approach in our application. We have a simple hierarchy similar to this: SuperSpecializedPerson extends SpecializedPerson extends (abstract) Person We've got two repositories for SuperSpecializedPerson and…
Philippe
  • 1,949
  • 4
  • 31
  • 57
0
votes
1 answer

Two collection of the Table per class hierarchy in the one class in the NHibernate/Conform

I faced with following case: I have table per class hierarchy: public abstract class Parent : BaseEntity, IHierarchyEntity { } public class ChildA : Parent { public virtual string Name { get; set; } } public class ChildB : Parent { …
Ivan Korytin
  • 1,832
  • 1
  • 27
  • 41
0
votes
0 answers

Unable to set field/property Store on entity type parameter_manual_input_pattern. See InnerException for details

I got this error when I try to add a new "parameter" object into database, I have: "parameter" abstract class "parameter_manual_input_pattern" class inherits "parameter" abstract class "parameter_store_pattern"class inherits "parameter" abstract…
0
votes
1 answer

When using TPH with Entity Framework, how do I make my OData only expose a particular type?

Because I'm supporting soft deletes in my database, I've chosen to sub-type my Thing entity as ActiveThing and DeletedThing... protected override void OnModelCreating(DbModelBuilder modelBuilder) { // TPH (table-per-hierarchy): …
bkwdesign
  • 1,953
  • 2
  • 28
  • 50
0
votes
0 answers

Set discriminator property in subclass - Entity Framework

I have the following problem. I'm building TPH inheritance with Entity Framework and I need to set discriminator column on existing property of subclass. Example: public abstract class Building { //... some properties public BuildingType…
chobotek
  • 77
  • 2
  • 6
0
votes
0 answers

Wrong mapping configuration on TPH inheritance in Entity Framework?

I tried to apply TPH inheritance strategy on my Domain with Code First and FluentApi. I have the following domain model: public abstract class Entity { public Guid Id { get; set; } public byte [] RowVersion { get; set; } } public class…
Iskander Raimbaev
  • 1,322
  • 2
  • 17
  • 35
0
votes
1 answer

Map viewmodel to model created with TPH pattern

I have one base class and 3 sub classes and single viemodel with all properties. I want in my controller create action to bind this viewmodel to concrete sub type. Here is my create action which doesn't work (I'm getting Error mapping…
0
votes
1 answer

TPH EF6.0: Cannot calculate the value of expression

I have 3 classes inherited from an abstract base class: abstract class PortTaskStep{ public Guid TaskID { get; set; } [ForeignKey("TaskID")] public virtual PortChangeTask PortChangeTask { get; set; } public virtual String…
李陈峰
  • 1
  • 1