You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even if TPT is considered slow, it is a boon for many real world business scenarios. If implemented properly and well thought of, TPT is not slow for a given need in most of the cases.
If possible, optimization can be done to TPT.
But its a very important feature for EF to be accepted for developing DDD applications.
The other method, Composition over Inheritance does not look viable since we cannot use interface property to create our model. Binding to a concrete type takes away the flexibility to customize the models. TPT makes the customization very easy and flexible.
Reacted by Salem Korayem, Jason Cavett, satyajit-behera, Andre Alves, Vlad Rudych, dimio, Valeriy Yurchenko, Ted van der Veen, Brandon, Mikhail Kantarovskiy and 287 more
Reacted by Steffen Mangold, Dirk Avondschool, Brian Mikinski, Mark, Sultanov, jsmith-jxe, EL MCHERQUI, Shimmy Weitzhandler, Rowland Shaw, Jochen Bamminger and 33 more
Update: we are planning to implement TPT. This comment is from 2015. Please read the rest of the thread, not just this comment.
The feeling from our team is that TPT is generally an anti-pattern and results in significant performance issues later on. While enabling it may make some folks "happier" to start with it ultimately just leads to issues. We are willing to consider it though, so we're leaving this open and will consider it based on the feedback we get.
Reacted by Vlad K, Ashraf Ali, Collin Sauve, Halid Cisse, Meinrad Jean-Richard, Shimmy Weitzhandler, majhoos, GlennEsh, Andriy Svyryd and satyajit-behera
Reacted by Søren Nguyen Boisen, Vadim Ovchinnikov, Ivan Kaurov, Brian Lowry, Pavel-Dolinski-Technosoft, Marvin S., César, Matthias Jauernig, Biscuits24_, Sebastien Roche and 63 more
We are in the process of implementing TPH at the moment, so you will be able to persist an inheritance hierarchy to a single table in the near future.
Reacted by Vlad K and Markus Schaber
Reacted by Jeffrey Palermo, Wellington Júnior, jgonte, NetMage, John Xiong, Rob Gibson, ghadzhigeorgiev, Aliaksei Radzevich, tedchirvasiu, Otabek and 3 more
Reacted by Salem Korayem, Mike Bovenlander and Umbra77
But it does not solve the main issue of extending a table. TPT becomes a necessity in practical business scenario. Otherwise, it may become a table with 100s of fields in it.
Reacted by Adrian, Ilya, Mikhail Kantarovskiy, Stéphane Mitermite, Shimmy Weitzhandler, Jeow Li Huan, Fernando JS, SimonBB, Lucas M Pereira, Marcel Bradea and 40 more
Reacted by Otabek and linxiao
Reacted by johnchandlerwatson, Lucas M Pereira, Jim, Steffen Mangold, Bryan Martin, Umbra77, Marek, Otabek, tedchirvasiu and Hicham
@satyajit-behera TPT is an inheritance mapping pattern. Are you referring to "Entity Splitting". i.e. Having a single entity mapped to more than one table?
TPT can be important for performance. Think of huge tables. Usually, you want only the absolutely required fields in such a table. TPH has column bloat, TPT is lean. Also, with TPT database statistics can be specialized for each type. This is important because different types can have vastly different data distributions.
TPT is quite an important pattern and I don't see why it would be considered an anti-pattern. An anti-pattern is a thing that is almost always the wrong choice. This does not seem to hold here.
Reacted by Muhammad Rehan Saeed, Ilya, Mikhail Kantarovskiy, Stéphane Mitermite, Ryan Southgate, Shimmy Weitzhandler, Fernando JS, SimonBB, Ivan R. Perez, Lucas M Pereira and 47 more
Reacted by Otabek
Reacted by Lucas M Pereira, Vadim Ovchinnikov, Johnny Santos, Dmitry Bogatykh, tedchirvasiu, Otabek, Hicham and Abdelrahman
@GSPP i agree with you. Having TPT is a must for an ORM and i think it was recurrent solution for a lot of problems in EF6 in the real world. I used it in my models a lot. One should be careful with the tools he uses, but that doesn't mean he shouldn't have those tools available. Both types of inheritance should be present in EF Core. Please include this scenario in the 7.0 release
Reacted by Fernando JS, Lucas M Pereira, Nick Quinn, Brian Lowry, Eduard Malakhov, Ronnie, NetMage, Kadir Atesoglu, Sultanov, Anton Veselov and 5 more
@rowanmiller I hope you will prioritize and include the TPT inheritance mapping for EF 7. All of us can discuss if some specific feature make it slow and get a workaround for the same. But the feature itself is very useful in business applications. Please include this in EF Core release. Thanks a lot.
👍 TPT inheritance may have some performance issues, but the design clarity it provides for real world scenarios outweighs them. I also do not feel that TPT inheritance is an "anti-pattern".
Reacted by pvasek, Adem Caglin, Muhammad Rehan Saeed, Jalal, Ilya, Mikhail Kantarovskiy, Stéphane Mitermite, Shimmy Weitzhandler, Jeow Li Huan, Fernando JS and 41 more
Agree 100% with @ToddThomson. This is another strong vote to add this feature ASAP. I think that TPH can be viewed as a SQL Server anti-pattern once the number of columns becomes unmanageable from a statistics and (more importantly) indexing viewpoint.
Reacted by Ilya, Jeow Li Huan, Fernando JS, Lucas M Pereira, Brian Lowry, Ronnie, Jim, Dennis, Steffen Mangold, John Xiong and 5 more
is that at some point you could have multiple Teachers/Students for one Person. By using the following design instead:
That happens in the real world, though. In my last year of college, I was a STUDENT in my courses, but also hired to be a TEACHER in the Cont Ed division (teaching AutoCad and Excel to senior citizens... tons of fun).
While a bird is not going to be both an Eagle and and a Kiwi, a person is totally able to be both a Student and a Teacher. Another example is a well-known online accounting system that doesn't allow a person (or a company) to be more that one of "supplier", "customer" and "employee", which means multiple records when a staff member has to be paid for some odd expense, or you both buy from and sell to another company.
The real world answer tends to be creating a "John Smith (Student)" and "John Smith (Teacher)" record, but that is confusing and leads to errors (when John moves and only one address is updated).
What's the right way to model those kinds of relationships?
@boomalator You could design it such that a Person (John Smith) can have many Jobs (Student and Teacher). It might be a many-to-many relationship because multiple Person can have the same Job.
@boomalator You could design it such that a Person (John Smith) can have Jobs (Student and Teacher). It might be a many-to-many relationship because multiple Person can have the same Job.
That would suggest to me that modeling Student and Teacher as inheriting from Person would be flawed as a practice and as an example.
For simple cases and examples, inheritance will work just fine. But it doesn't mean that we need to keep modeling it as inheritance when the scope becomes bigger than what it was initially designed for. It also doesn't mean that we should avoid using inheritance at all. It really depends on the domain you're working on. 😀
Reacted by Arthur Vickers and Juliano Leal Goncalves
is that at some point you could have multiple Teachers/Students for one Person. By using the following design instead:
That happens in the real world, though. In my last year of college, I was a STUDENT in my courses, but also hired to be a TEACHER in the Cont Ed division (teaching AutoCad and Excel to senior citizens... tons of fun).
While a bird is not going to be both an Eagle and and a Kiwi, a person is totally able to be both a Student and a Teacher. Another example is a well-known online accounting system that doesn't allow a person (or a company) to be more that one of "supplier", "customer" and "employee", which means multiple records when a staff member has to be paid for some odd expense, or you both buy from and sell to another company.
The real world answer tends to be creating a "John Smith (Student)" and "John Smith (Teacher)" record, but that is confusing and leads to errors (when John moves and only one address is updated).
What's the right way to model those kinds of relationships?
This comes up a lot at Facebook for example, where their Graph API models everything as Nodes (ie: entities) and Edges (ie: relationships), as well as Fields which store the data about those entities/relationships. These are used to model everything including People, Organizations, Pages, Events, Groups etc.
While you don't necessarily have to abstract your entire data base into an object graph like Facebook does, the moment you start hitting 'roles' that a person can take on (ie: them being a Student, a Teacher, a Father, Investor etc.)... inheritance is likely a misfit for modelling the real-world structure at hand.
Think about the domain you are trying to model and try to pick the right level of abstraction. Is it a Position that might have a title, length of employment etc. (such as for recruiting/LinkedIn), or something more/less abstract like a Job (ie: job would not appropriately account for a sitting on an executive board or volunteering for something, as those are not technically 'jobs').
is that at some point you could have multiple Teachers/Students for one Person. By using the following design instead:
That happens in the real world, though. In my last year of college, I was a STUDENT in my courses, but also hired to be a TEACHER in the Cont Ed division (teaching AutoCad and Excel to senior citizens... tons of fun).
While a bird is not going to be both an Eagle and and a Kiwi, a person is totally able to be both a Student and a Teacher. Another example is a well-known online accounting system that doesn't allow a person (or a company) to be more that one of "supplier", "customer" and "employee", which means multiple records when a staff member has to be paid for some odd expense, or you both buy from and sell to another company.
The real world answer tends to be creating a "John Smith (Student)" and "John Smith (Teacher)" record, but that is confusing and leads to errors (when John moves and only one address is updated).
What's the right way to model those kinds of relationships?
Okay, indeed not such a good example. The example of Bird <- Kiwi and Bird <- Eagle is more applicable if you're talking about Inheritance. Or another example:
Vehicle <- Car
<- Bike
<- Motorbike
The case you're talking about, eg.
Member <- Customer
<- Supplier
<- Contact
Where a Member can be both Customer, Supplier and Contact is not an example of inheritance, but can be modelled like this:
public class Member
{
public List<Customer> Customers { get; set; }
public List<Supplier> Suppliers { get; set; }
public List<Contact> Contacts { get; set; }
}
public class Customer
{
public Member Member { get; set }
}
public class Supplier
{
public Member Member { get; set }
}
public class Contact
{
public Member Member { get; set }
}
Sorry, but I'm not seeing a clear story here for either the 'for' or the 'against' argument regarding TPT.
Certainly, the obvious use case here has to be the PostgreSQL hierarchical table arrangement.
While I understand the natural inclination for a Microsoft framework is to advance integration scenarios that support well-established database platforms.
But discussions of samples and conceptual representations of TPT as a query-syntax-structure problem rather than a data-entity-relationship challenge seem intentionally designed to avoid the value of hierarchical tables in favor of the TPT implementation pattern (or style, depending on how it is conceived).
My viewpoint is that those posting requests for TPT are making a DB design and implementation argument in favor of the established value of the hierarchical table use case.
But the perspective of the EF team is that all issues are aspects of the conceptual framework of TPH/TPT and its variants.
All of these are implementation issues, not use cases, and that perspective drives this discussion, and the decision it should be targeting toward basing this fundamental framework design choice exclusively on what is essentially a SQL Query Optimization decision tree.
I believe the correct elucidation of the TPT question, and the path to the answer lies in an examination of the source code of PostgreSQL Hierarchical Table implementation, since none of the requesters are expressing a requirement based on a modified or replaced TPT strategy, but are looking for the data design and entity-relationship efficiency that isolates Application-side Entities from the repetitive server-side utility and tracking data tables that are attached by means of relations to true 'entity rows' tables that are mapped to objects in code by EF and EF Core.
This pattern of isolation of entity-specific database tables to utility-generic database tables is the essence and the point of the hierarchical table structure. Without a basic explication of that Functionality, no real communication on this topic will occur.
But all parties should do the basic research necessary to be able to explain what they are trying to achieve in this discussion and why they may be trying to conflate a TPT implementation pattern and a Data Storage design pattern.
@kimballjohnson TPT support was already introduced as an EF Core feature into version 5.0, so the discussion may be moot at this point.
Regardless, the PostgreSQL hierarchical table arrangement is, well, PostgreSQL-specific. One could argue that it should exist in MySQL and SQL Server, but that's quite out of EF Core's scope. Note that PostgreSQL hierarchical tables are also considered legacy by some.
So, concretely speaking, users needing inheritance mapping today - on non-PostgreSQL databases - need to make a choice between TPH and TPT; and TPT is known to have problematic perf in some scenarios because of the additional JOINs it introduces(see more about this in our docs).
Shay,
It’s kind of you to take the time to provide an explanation.
And yes, it’s become clear to me that TFT has been implemented in EF Core.
However, my remarks were focused on the lack of communication in the discussion in the Discus thread attached to the Issue regarding TPH and TPT.
Of course, as soon as I submitted my post, I was able to recognize that the thread was closed and the decision to implement had already been made.
So, the question of TPT in EF core is moot.
However, the question of whether the implementation of TFT you have devised will be robust and manageable at scale remains.
To restate the point of my perspective, the two sides of the issue in the Discus thread were each examples of lines of logic that were skew and could never meet.
But since I was not alert to the closure of the thread, all of this is moot.
I apologize for initiating a mail cycle that could provide no value.
But, again, thanks for the time to try to clarify the matter for me.
Kimball Johnson
From: Shay Rojansky ***@***.***>
Sent: Sunday, May 16, 2021 3:41 AM
To: dotnet/efcore ***@***.***>
Cc: Kimball Johnson ***@***.***>; Mention ***@***.***>
Subject: Re: [dotnet/efcore] Relational: TPT inheritance mapping pattern (#2266)
@kimballjohnson<https://github.com/kimballjohnson> TPT support was already introduced as an EF Core feature into version 5.0, so the discussion may be moot at this point.
Regardless, the PostgreSQL hierarchical table arrangement is, well, PostgreSQL-specific. One could argue that it should exist in MySQL and SQL Server, but that's quite out of EF Core's scope. Note that PostgreSQL hierarchical tables are also considered legacy by some<https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_table_inheritance>.
So, concretely speaking, users needing inheritance mapping today - on non-PostgreSQL databases - need to make a choice between TPH and TPT; and TPT is known to have problematic perf in some scenarios because of the additional JOINs it introduces(see more about this in our docs<https://docs.microsoft.com/en-us/ef/core/performance/modeling-for-performance#inheritance-mapping>).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#2266 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAP65M4HUUFSRSFCDDK4ZMLTN6OK3ANCNFSM4BE44Q4Q>.
Activity
rowanmiller commentedon May 29, 2015
Update: we are planning to implement TPT. This comment is from 2015. Please read the rest of the thread, not just this comment.
The feeling from our team is that TPT is generally an anti-pattern and results in significant performance issues later on. While enabling it may make some folks "happier" to start with it ultimately just leads to issues. We are willing to consider it though, so we're leaving this open and will consider it based on the feedback we get.satyajit-behera commentedon May 29, 2015
Thanks. Issue is the absence of any alternative to build an OO application. Even Composition using interfaces does not look viable for now.
rowanmiller commentedon May 29, 2015
We are in the process of implementing TPH at the moment, so you will be able to persist an inheritance hierarchy to a single table in the near future.
satyajit-behera commentedon May 29, 2015
But it does not solve the main issue of extending a table. TPT becomes a necessity in practical business scenario. Otherwise, it may become a table with 100s of fields in it.
anpete commentedon May 29, 2015
@satyajit-behera TPT is an inheritance mapping pattern. Are you referring to "Entity Splitting". i.e. Having a single entity mapped to more than one table?
satyajit-behera commentedon May 30, 2015
@anpete I am referring to One table per inherited entity type.
GSPP commentedon Jun 15, 2015
TPT can be important for performance. Think of huge tables. Usually, you want only the absolutely required fields in such a table. TPH has column bloat, TPT is lean. Also, with TPT database statistics can be specialized for each type. This is important because different types can have vastly different data distributions.
TPT is quite an important pattern and I don't see why it would be considered an anti-pattern. An anti-pattern is a thing that is almost always the wrong choice. This does not seem to hold here.
santanaguy commentedon Jun 23, 2015
@GSPP i agree with you. Having TPT is a must for an ORM and i think it was recurrent solution for a lot of problems in EF6 in the real world. I used it in my models a lot. One should be careful with the tools he uses, but that doesn't mean he shouldn't have those tools available. Both types of inheritance should be present in EF Core. Please include this scenario in the 7.0 release
satyajit-behera commentedon Jul 3, 2015
@rowanmiller I hope you will prioritize and include the TPT inheritance mapping for EF 7. All of us can discuss if some specific feature make it slow and get a workaround for the same. But the feature itself is very useful in business applications. Please include this in EF Core release. Thanks a lot.
ToddThomson commentedon Jul 16, 2015
👍 TPT inheritance may have some performance issues, but the design clarity it provides for real world scenarios outweighs them. I also do not feel that TPT inheritance is an "anti-pattern".
konstantin999 commentedon Jul 31, 2015
@rowanmiller TPT inheritance is the reason why we can not use EF in our projects :( It would be nice if it will included in EF Core.
http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1015337-tpt-table-per-type-inheritance-performance
https://entityframework.codeplex.com/workitem/2332
konstantin999 commentedon Jul 31, 2015
For example, in DO this problem was solved by including a TypeId field in all types. http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v3.9/html/P_DataObjects_NET_DataObject_TypeID.htm
AndyNewland commentedon Aug 27, 2015
Agree 100% with @ToddThomson. This is another strong vote to add this feature ASAP. I think that TPH can be viewed as a SQL Server anti-pattern once the number of columns becomes unmanageable from a statistics and (more importantly) indexing viewpoint.
314 remaining items
boomalator commentedon Aug 23, 2020
That happens in the real world, though. In my last year of college, I was a STUDENT in my courses, but also hired to be a TEACHER in the Cont Ed division (teaching AutoCad and Excel to senior citizens... tons of fun).
While a bird is not going to be both an Eagle and and a Kiwi, a person is totally able to be both a Student and a Teacher. Another example is a well-known online accounting system that doesn't allow a person (or a company) to be more that one of "supplier", "customer" and "employee", which means multiple records when a staff member has to be paid for some odd expense, or you both buy from and sell to another company.
The real world answer tends to be creating a "John Smith (Student)" and "John Smith (Teacher)" record, but that is confusing and leads to errors (when John moves and only one address is updated).
What's the right way to model those kinds of relationships?
gojanpaolo commentedon Aug 23, 2020
@boomalator You could design it such that a
Person(John Smith) can have manyJobs(Student and Teacher). It might be a many-to-many relationship because multiplePersoncan have the sameJob.boomalator commentedon Aug 23, 2020
That would suggest to me that modeling Student and Teacher as inheriting from Person would be flawed as a practice and as an example.
gojanpaolo commentedon Aug 23, 2020
For simple cases and examples, inheritance will work just fine. But it doesn't mean that we need to keep modeling it as inheritance when the scope becomes bigger than what it was initially designed for. It also doesn't mean that we should avoid using inheritance at all. It really depends on the domain you're working on. 😀
marchy commentedon Aug 23, 2020
This is a wonderful question @boomalator.
This comes up a lot at Facebook for example, where their Graph API models everything as Nodes (ie: entities) and Edges (ie: relationships), as well as Fields which store the data about those entities/relationships. These are used to model everything including People, Organizations, Pages, Events, Groups etc.
While you don't necessarily have to abstract your entire data base into an object graph like Facebook does, the moment you start hitting 'roles' that a person can take on (ie: them being a Student, a Teacher, a Father, Investor etc.)... inheritance is likely a misfit for modelling the real-world structure at hand.
Think about the domain you are trying to model and try to pick the right level of abstraction. Is it a Position that might have a title, length of employment etc. (such as for recruiting/LinkedIn), or something more/less abstract like a Job (ie: job would not appropriately account for a sitting on an executive board or volunteering for something, as those are not technically 'jobs').
PieterjanDeClippel commentedon Aug 24, 2020
Okay, indeed not such a good example. The example of
Bird <- KiwiandBird <- Eagleis more applicable if you're talking about Inheritance. Or another example:The case you're talking about, eg.
Where a
Membercan be bothCustomer,SupplierandContactis not an example of inheritance, but can be modelled like this:Then a member can be both
CustomerandSupplierAndriySvyryd commentedon Oct 10, 2020
@RonOsmo Please file those as separate issues with small runnable projects that show the unwanted behavior
kimballjohnson commentedon May 16, 2021
Sorry, but I'm not seeing a clear story here for either the 'for' or the 'against' argument regarding TPT.
Certainly, the obvious use case here has to be the PostgreSQL hierarchical table arrangement.
While I understand the natural inclination for a Microsoft framework is to advance integration scenarios that support well-established database platforms.
But discussions of samples and conceptual representations of TPT as a query-syntax-structure problem rather than a data-entity-relationship challenge seem intentionally designed to avoid the value of hierarchical tables in favor of the TPT implementation pattern (or style, depending on how it is conceived).
My viewpoint is that those posting requests for TPT are making a DB design and implementation argument in favor of the established value of the hierarchical table use case.
But the perspective of the EF team is that all issues are aspects of the conceptual framework of TPH/TPT and its variants.
All of these are implementation issues, not use cases, and that perspective drives this discussion, and the decision it should be targeting toward basing this fundamental framework design choice exclusively on what is essentially a SQL Query Optimization decision tree.
I believe the correct elucidation of the TPT question, and the path to the answer lies in an examination of the source code of PostgreSQL Hierarchical Table implementation, since none of the requesters are expressing a requirement based on a modified or replaced TPT strategy, but are looking for the data design and entity-relationship efficiency that isolates Application-side Entities from the repetitive server-side utility and tracking data tables that are attached by means of relations to true 'entity rows' tables that are mapped to objects in code by EF and EF Core.
This pattern of isolation of entity-specific database tables to utility-generic database tables is the essence and the point of the hierarchical table structure. Without a basic explication of that Functionality, no real communication on this topic will occur.
But all parties should do the basic research necessary to be able to explain what they are trying to achieve in this discussion and why they may be trying to conflate a TPT implementation pattern and a Data Storage design pattern.
roji commentedon May 16, 2021
@kimballjohnson TPT support was already introduced as an EF Core feature into version 5.0, so the discussion may be moot at this point.
Regardless, the PostgreSQL hierarchical table arrangement is, well, PostgreSQL-specific. One could argue that it should exist in MySQL and SQL Server, but that's quite out of EF Core's scope. Note that PostgreSQL hierarchical tables are also considered legacy by some.
So, concretely speaking, users needing inheritance mapping today - on non-PostgreSQL databases - need to make a choice between TPH and TPT; and TPT is known to have problematic perf in some scenarios because of the additional JOINs it introduces(see more about this in our docs).
kimballjohnson commentedon May 18, 2021