A technique that maps an inheritance hierarchy of objects to a single table in relational database.
Questions tagged [table-per-hierarchy]
133 questions
1
vote
1 answer
Create Entity Framework TPH Discriminator column by Data Annotation
I would like to create Discriminator column by Data Annotation.
[Table("Book")]
public partial class Book
{
public long BookID { get; set; }
[StringLength(100)]
public string name { get; set; }
public int? page { get; set;…

Hamid
- 817
- 1
- 13
- 29
1
vote
1 answer
Any way to instruct Entity Framework to map from column to Model property in code-first, table-per-hierarchy approach?
We are using Entity Framework 6.1 in our MVC application, using code-first and table-per-hierarchy approach since we are developing from scratch and we think this way is suitable for fast development. But now I have a question: say I have one base…

tete
- 4,859
- 11
- 50
- 81
1
vote
1 answer
Recursively serialize multiple Datatable hierarchies to JSON object
I want to serialize multiple DataTables to JSON which are interrelated and it is possible there will be additional table are all set in the mapping table. In this case, I have 3 DataTables.
Table A as parent
Table B as the child of Table A
Table C…

frenzybluez
- 29
- 6
1
vote
1 answer
Entity Framework Table per Hierarchy not creating Discriminator
I created an inheritance hierarchy after a few migrations. Now when I update the database using code first migrations, code-first is not automatically creating the discriminator field. I have since dropped the table and recreated it (using…

tonyapolis
- 201
- 2
- 12
1
vote
1 answer
Entity Framework Table Per Hierarchy Inserting Multiple Id Columns
I have seriously spent two work days trying to a TPH setup from Database First to Code first. The Error I get is Something like "Invalid Column Name Entity_EntityId/ Entity_Entity_Id1"
I've drawn up a very basic reproduction of the issue like so:
…

Chazt3n
- 1,641
- 3
- 17
- 42
1
vote
0 answers
Table per hierarchy not default behavior of EF6
I'm trying to map these three classes to one EF table. In this scenario, my base class actually has a base Entity class, is this causing my issue? I'm not finding any examples that cover a scenario where the default behavior isn't handled properly.…

Chazt3n
- 1,641
- 3
- 17
- 42
1
vote
1 answer
Entity Framework 6.1.1 ignores ProxyCreationEnabled settings
I have a context class, and at some point I need to get data from database in my POCO classes, so that I can serialize that data and send over to my web service. I do not want to deserialize proxies on the other end, but I am not able to force EF to…

DarkDeny
- 1,750
- 2
- 21
- 31
1
vote
1 answer
Entity framework Fluent API does not consider base class properties
EF 6.1 :
We just started a project that has a lot pf inheritance. The selected inheritance db mapping type is the table per hierarchy. The problem is that when trying to generate the migration using the add-migration, the following error is thrown :…

Whoami
- 334
- 4
- 16
1
vote
1 answer
EF6 code-first Discriminator from Backupfile
I have a backup file of an old database where I havn't used EF. Now I create a new database with EF code first fluent api with table per hierachy. That's why I have a not-nullable discriminator column. In my backup file there is no discriminator. So…

Oliver Müller
- 545
- 1
- 5
- 17
1
vote
1 answer
Entity Framework 6.1 Code First TPH/TPT hybrid mapping issue
I have a model where most of the entities inherit the same base functionality. That functionality is encapsulated in an abstract base class. Above that, there are two branches of functionality and thus there are two abstract classes that inherit…

joelmdev
- 11,083
- 10
- 65
- 89
1
vote
0 answers
How to find out the table name of an entity class type in Table-Per-Hierarchy?
I was found following code to find out the table name of an entity given entity class type using GetTableName method. But GetEntitySet method fails, because in TPH the table name, and therefore seemingly EntitySetBase is different than the subtype.…

ciuncan
- 1,062
- 2
- 11
- 25
1
vote
2 answers
Issue with many-to-many relationship + TPH inhertitance in Entity Framework 6
I am running into an issue with EF6, though I'm fairly sure that this applies to previous versions that support this type of mapping. I fear I know the answer to the question at hand, but I hope that I am doing something wrong, or there is a better…

joelmdev
- 11,083
- 10
- 65
- 89
1
vote
2 answers
Multiple Inheritance with Entity Framework with TPH
Further to this question:
Entity Framework TPH with multiple abstract inheritance and VS.2008 sp1 .net 3.5 c#
I decided to add Organizations and a School. Organization(abstract) inherits from Party, and School(concrete) inherits from…

itchi
- 1,683
- 14
- 30
1
vote
1 answer
Entity Framework inheritance moving a foreign key to a child in TPH
I'm using table per hierarchy inheritance within my enitity model and I have a parent table that contains relationships to other tables via foreign keys.
My parent table (Product) has a FK relationship to another table which in EF resolves to a…

Adam Cooper
- 8,077
- 2
- 33
- 51
1
vote
1 answer
EF5 TPH Extra Foreign Keys being generated - How to get rid of them?
This is a sample app I've concocted which produces the same behaviour as my actual much-more-complex app.
I'm obviously missing some configuration aspect somewhere, but can't figure it out for the life of me. For some reason, each collection in my…

Dave R
- 1,626
- 19
- 28