Questions tagged [table-per-hierarchy]

A technique that maps an inheritance hierarchy of objects to a single table in relational database.

133 questions
1
vote
2 answers

EF: TPH implementation with Fluent mapping throws Invalid Column Name exception

Here is my implementation. public partial class Person { #region Constructors public Person() { PersonExpirableCredentials = new List(); } #endregion Constructors #region…
1
vote
1 answer

Cannot select table for discriminator (model-first)

I'm trying to kick off a project needing table-per-hierachy. I've done this in the past with NHibernate, but we want to avoid having to hand edit XML mapping files - so are trying to use Entity Framework and it's Designer. I've been following this…
bly
  • 1,532
  • 1
  • 12
  • 19
1
vote
2 answers

How to properly map nested subclasses using hibernate

How do I nest subclasses with Hibernate? For example, I have the following class hierarchy: PageElement - PageParagraph - PageImage - PageVideo - PageAudio - PageQuestion - PageFillInTheBlankQuestion - PageOpenEndedQuestion -…
egervari
  • 22,372
  • 32
  • 121
  • 175
1
vote
1 answer

EF : MVC : ASP: TPH Error - Store update, insert, or delete ... number of rows (0). Entities ... modified or deleted ... Refresh ObjectStateManager

Error Message: "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries." Hello All, I've created a Code First…
1
vote
0 answers

Entity Framework how to setup relationships with Inheritance types

I currently have the following classes in my EF based project. Data is stored in a SQL Database using the Table per Hierarchy (TPH) configuration : class Lot { Building building ... } class Building { string name {get; set;} …
1
vote
0 answers

Confusion about which inheritance strategy to use with EF6 (CodeFirst)

I have a question about inheritance strategies with the code first approach of entity framework. Currently i have to implement a variety of question tables to our database. This is my current QuestionBase class, which has all the properties every…
1
vote
2 answers

EF Core, table-per-hierarchy and referencing entity of the same base class generates error

We have contacts are stored via table-per-hierarchy, A contact is either a company or a person and a person always belongs to a company. Both inherit from contact. EF Core 2.1 is used. It looks like this public abstract class Contact { public…
Arikael
  • 1,989
  • 1
  • 23
  • 60
1
vote
0 answers

Primary Key Discriminator persisted with default value in EF Core

Background I'm using code first with mapping classes in EF Core at my current project. One of my entities, Action is an abstract class that has multiple inheritors ActionOne, ActionTwo, and ActionThree. I'm using TPH with an enum discriminator…
Shay
  • 1,680
  • 2
  • 26
  • 39
1
vote
1 answer

Entity Framework 4 - TPH Inheritance in Features CTP5 (code first) with "IS NULL" discriminator

Hey guys, I'm trying to create a TPH mapping on a hierarchy where the discriminating clause is the classical "IS NOT NULL" / "IS NULL" case. Here is the example, database wise: CREATE TABLE info.EducationTypes ( ID INT NOT NULL PRIMARY KEY, …
Kralizek
  • 1,999
  • 1
  • 28
  • 47
1
vote
1 answer

Entity Framework: Query Multiple Types

I have a EF6 code-first model with inheritance, for example: [Table("Things")] abstract class AbstractThing { public int ThingId { get; set; } public string Color { get; set; } } class Car : AbstractThing { public string Brand { get; set;…
Efrain
  • 3,248
  • 4
  • 34
  • 61
1
vote
2 answers

EF1: Filtering derived types of entity class using .OfType<> by passing a string value

I have a situation where I'm trying to filter a LINQ select using a derived sub class. ctx.BaseEntity.OfType() - this works fine. However I'd like to do this using a string value instead. I've come across a performance barrier when I have…
1
vote
1 answer

Mapping fragments exception with Table-per-Hierarchy (Entity Framework 4)

If i have SQL Server tables like this: Location ---------- LocationId int PK Field1 int Field2 int etc Score ------------------------------------ LocationId int PK, FK IsSingleLevel bit PK (discriminator) Field1 int Field2 int etc Technically…
1
vote
0 answers

Entity Framework reverse POCO generator and Table-Per-Hierarchy

I have an existing SQL Server database using Entity Framework code-first with a table-per-hierarchy option. This means there is a Discriminator column in table Persons representing the different possible types - let's say "Doctor" and "Nurse". Now,…
1
vote
0 answers

Is it possible to specify ranges instead of particular values for TPH inheritance model?

I need to discriminate types on the following condition: 0 - type A >0 - type B Is it achievable using EF6/7 ?
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
1
vote
0 answers

Entity Framework TPH: how to map foreign keys to DB columns

I am using Table-Per-Hierarchy pattern (same DB table for all derived classes), like this: Base class: public class Person { public int Id { get; set; } public string Name { get; set; } } A few derived classes, some of them having Address,…
Tomas
  • 449
  • 5
  • 11
1 2 3
8 9