ZZZ Code AI
Report Issues
Suggest Features
Blog/Newsletter
Login
EF Core Tools
Chat
Code Explain
More Tools
How to map entities in the 'OnModelCreating' method to implement TPC inheritance in EF Core?
<p>To implement the TPC inheritance strategy in EF Core, you need to:</p> <ol> <li>Call the <code>UseTpcMappingStrategy</code> method for your root entity</li> <li>Call the <code>ToTable([TableName])</code> method for every concrete entity</li> </ol> <p>Here is an example:</p> <pre><code class="language-csharp">protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Animal>().UseTpcMappingStrategy(); modelBuilder.Entity<Cat>().ToTable("Cats"); modelBuilder.Entity<Dog>().ToTable("Dogs"); } </code></pre> <p>In this example, the <code>Animal</code> is an abstract class, meaning you don't map it to a table. However, if the <code>Animal</code> is a concrete class, you must also map it to a table like other concrete classes.</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
?