ZZZ Code AI
Report Issues
Suggest Features
Login
EF Core Tools
Chat
Code Explain
More Tools
Can I have multiple DbSet instances for each class within a TPH inheritance in EF Core?
<p>Yes, every concrete and abstract type can be in its own <code>DbSet</code>. Here is an example:</p> <pre><code class="language-csharp">public DbSet<Animal> Animals { get; set; } public DbSet<Cat> Cats { get; set; } public DbSet<Dog> Dogs { get; set; } </code></pre> <p>In this example, we have mapped the abstract <code>Animal</code> type to the <code>DbSet<Animal></code> and both concrete types to <code>DbSet<Cat></code> and <code>DbSet<Dog></code>.</p> <p>When you query the <code>DbSet<Animal></code>, the result will be a list of <code>Animal</code>, which will be either of <code>Cat</code> or <code>Dog</code> type.</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
?