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 TPC inheritance in EF Core?
<p>Yes, you can have multiple <code>DbSet</code> instances, and it's often recommended based on how you intend to query your entities.</p> <p>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 root entity <code>Animal</code> even if it is an abstract class. When you query the <code>DbSet<Animal></code>, the result will be a list of <code>Animal</code> objects, each of which could be an instance of either <code>Cat</code> or <code>Dog</code>.</p> <p>Furthermore, you can query the Cats or Dogs tables directly using their corresponding <code>DbSet</code>.</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
?