ZZZ Code AI
Report Issues
Suggest Features
Login
EF Core Tools
Chat
Code Explain
More Tools
Is there any performance issue related to TPC inheritance in EF Core?
<p>The TPC inheritance could become slow if you have too many concrete types.</p> <p>If you query the root entity, a SQL will be created with a <code>UNION ALL</code> join that will include all tables from your concrete class.</p> <pre><code class="language-sql">SELECT [ColumnList], 'DiscriminatorName1' AS [Discriminator] FROM [TableName1] WHERE [predicate] UNION ALL SELECT [ColumnList], 'DiscriminatorName2' AS [Discriminator] FROM [TableName2] WHERE [predicate] UNION ALL SELECT [ColumnList], 'DiscriminatorName3' AS [Discriminator] FROM [TableName3] WHERE [predicate] UNION ALL SELECT [ColumnList], 'DiscriminatorName4' AS [Discriminator] FROM [TableName4] WHERE [predicate] </code></pre> <p>There is no problem if you have only 2 or 3 tables, but if you implement a strategy with many concrete classes, you might end up with some performance issues when querying.</p> <p>That is one of the reasons why this is recommended to only have 2 or 3 concrete classes in the TPC strategy.</p>
Sponsored by
Entity Framework Extensions
This field is required
A text with a minimum of 10 characters is required
Send
Legal & Licensing
Answer generated by AI may produce inaccurate information about code, people, facts, and more.
Advertising Break!
5
seconds left
Did you know...
That you can now sponsor this project on
GitHub
?