Questions tagged [table-per-hierarchy]

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

133 questions
0
votes
1 answer

nHiberbate: Table per hierarchy - SchemaExport problem

I am using nhibernate to map the following classes: public class DeviceConfig : EntityBase { public virtual string Name { get { return m_Name; } set { SetValue(ref m_Name, value); } } public virtual string…
Paul
  • 5,514
  • 2
  • 29
  • 38
0
votes
1 answer

Persisting one table per class hierarchy using NHibernate without discriminator?

I have an interface and a class which implements this interface. public interface IPhase { string Description { get; set; } int Id { get; } string Phase { get; set; } } public class Phase : IPhase { // Implementation…
0
votes
1 answer

Can I have two foreign keys from the same table key in a table-per-hierarchy inheriting table somehow?

.NET Core 2.2: I have a table-per-hierarchy (TPH) inheritance and I have customer and agent as inheriting from membership. Now I try and create a purchase order and want to add both their membership Ids as foreign keys but I can't, because that…
John Ashmore
  • 1,015
  • 1
  • 10
  • 25
0
votes
1 answer

Fluent NHibernate - mixing table-per-subclass and table-per-class-hierarchy

Give the following structure, MyBaseClass { public int Id {get; private set;} } MySubclassWithDiscriminator : MyBaseClass { } MySubclass : MyBaseClass { public string SomeThing {get; set;} } How would I use Fluent NH to map these correctly,…
rbellamy
  • 5,683
  • 6
  • 38
  • 48
0
votes
1 answer

.Net Core & Entity Framework Core - access properties of subclass in model using Table Per Hierarchy

I'm quite new to .Net Core & Entity Framework. I'm working on a .Net Core project that has a database that was created using the Code First Approach. The following inheritance structure exists in the model (pseudo-code): public abstract class…
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
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 load a table per hierarchy type from a DbDataReader with entity framework?

I tried calling ObjectContext.Translate where T is the abstract base type of a table-per-hierarchy entity. If the DbDataReader is streaming back all the columns of the underlying table, I thought this method would be able to construct the…
Triynko
  • 18,766
  • 21
  • 107
  • 173
0
votes
0 answers

How to query for entities of all types but one in a table per hierarchy?

I'm trying to do something that would seem very simple. I want to query for all types in a table per hierarchy, except for one type. This has to run as a single (pageable) database query. To return a single type, I can call…
Triynko
  • 18,766
  • 21
  • 107
  • 173
0
votes
0 answers

How can I map Entity Framework TPH with identical types and Single Discriminator?

Database schema: Id int Identity NOT NULL Name nvarchar(50) Discriminator nvarchar(20) NULL Database data: 1, 'John Doe', 'Manager' 2, 'Jane Doe', 'Supervisor' C# Entities: public abstract class Employee { public Int32 Id {get;set;} …
jwize
  • 4,230
  • 1
  • 33
  • 51
0
votes
2 answers

Entity Framework adds redundant duplicate discriminator column to table

I've been searching already for hours and I can't seem to find the issue. I am building an Entity Framework Fluent Api Code First TPH app. When I Add-Migration EF add's my "Type" column just fine, but it also adds a redundant Discriminator column…
0
votes
1 answer

Table-per-hierarchy mapping when subclasses have not-nullable fields?

I have a class hierarchy with an abstract base class and 4-5 subclasses. I want to use NHibernate's table-per-class-hierarchy mapping method to map these to a single database table to reduce the number of joins my queries generate. However, one of…
Brant Bobby
  • 14,956
  • 14
  • 78
  • 115
0
votes
1 answer

Entity Framework TPH Inheritance Code First oftype

I'm not quite sure how to solve this problem properly. I have a class Appointment and a class AppointmentSeries with inheritance from Appointment. My database is set up code-first with TPH. Now when I get the database, I want to get all rows with…
0
votes
1 answer

EF - Extract all record of specific type table per hierarchy

In my EF context I have a hierarchy of classes, managed with the table per hierarchy approach. Therefore I have a base abstract class and a bunch of classes that derive from it: public abstract class BaseClass { [Required] public int Id…
user449689
  • 3,142
  • 4
  • 19
  • 37
0
votes
1 answer

How to use TPH (Table Per Hierarchy) with ASP.NET Identity 2

I use ASP.NET Identity 2 in an MVC5 project and there are 2 type of user classes called Student and Coordinator as shown below. On the other hand, I tried to follow TPH (Table Per Hierarchy) approach so that using the same entity for both type of…
1 2 3
8 9