.NET Data Community Standup - TPH, TPT, and TPC Inheritance mapping with EF Core

preview_player
Показать описание
Type inheritance hierarchies as used in object-oriented programming do not map naturally to relational database schemas. In this live stream, we will look at different strategies for inheritance mapping when using EF Core with a relational database. This includes table-per-hierarchy (TPH) mapping, table-per-type (TPT) mapping, and table-per-concrete type (TPC) mapping, which is new in EF Core 7.0 preview 5. We will look at the consequences of the mapping on the generated SQL and consider the performance and storage implications. This will result in some guidance as to when each strategy should be used.





#entityframework #efcore #orm
Рекомендации по теме
Комментарии
Автор

00:56:53 TPC tables can use unique sequence ID by using the following.
.Property(e => VALUE FOR [AnimalIds]");

01:08:00 TPH tables can use IsSparse() to reduce the space of null data, but Perf. may be sacrified.
01:24:12 TPH tables may use Discriminator as Enum to improve the perf.
01:26:34 TPC tables can use UseHiLo() with SQL. SQL-Lite does not support UseHiLo().
01:30:13 The reason to use "await context.AddRangeAsync()" is UseHiLo().
01:33:00 HiLo confuses a lot of people because of the keys-gap .
01:35:00 Arthur recommended not using HiLo for simplicity.
01:37:25 If you update one raw at a time, you don't need HiLo.

PanosKao
Автор

how about I want a unique index in some value of the base table (in TPC) ?

AnNguyen-doec
Автор

Is it still necessary to define a sequence for the Id field when using TPC stratgey in EF Core 8? Thanks!

malkythealky
Автор

Where can I find an working example doing this ? Like a small project ?

johanredander
Автор

I still do not understand how Human.FavoriteAnimal navigation will get the right Animal type, you guys just touched the point that there is no foreign key constraint between Human and Animal which is a natural limitation that comes with TBC, but how does ef handle the navigation?! are we going to left join all child tables?

mhDuke
Автор

A varchar discriminator column hurts performance. Either use char(1) or a numeric value.

alexisfibonacci