Entity Framework 7 TPH, TPT and TPC inheritance mapping performance benchmarks

Entity Framework 7 will support Table-per-Concrete (TPC) type inheritance mapping as introduced in this blog post on devblogs.microsoft.com. This is awesome as although similar to the Table-per-Type (TPT) approach, TPC overcomes many of the performance issues associated with TPT.

I’ve used the Animal Hierarchy from the above blog post…

… combined with a variation of the TPH v TPT benchmark on Microsofts Modeling for Performance – EF Core page to see how the new TPC type performs against the other approaches.

I’ve done two separate benchmarks (per mapping type) which we can see below to pull back all animals (the root type) and to pull back all cats (single leaf type). There are 5000 records in total.

Click on the image for a larger view in a new tab…

We can see when all animals (base type) are returned TPH performs quickest, this is because everything is in one table. On the other hand when we looking for Cats (concrete type) TPC performs quickest. We can also see that TPT appears to not be a good performer for either scenario, mostly likely due to all the joins required to get the data back.

The above results tie in with advice from the Entity Framework team in their Announcing Entity Framework 7 Preview 5 blog post…

Leave a Reply

Your email address will not be published.