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 TPT inheritance in EF Core?
<p>Sure, it's always recommended to have multiple <code>DbSet</code> when working with any inheritance such as <code>TPT</code>. It makes it easier to query your entities when you already know exactly the type.</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,</p> <ul> <li><strong>The <code>DbSet<Animal> Animals</code></strong>: Allow you to query any type that inherits from <code>Animal</code> such as <code>Cat</code> and <code>Dog</code>.</li> <li><strong>The <code>DbSet<Cat> Cats</code></strong>: Allow you to directly query <code>Cat</code>.</li> <li><strong>The <code>DbSet<Dog> Dogs</code></strong>: Allow you to directly query <code>Dog</code>.</li> </ul>
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
?