ZZZ Code AI
Report Issues
Suggest Features
Login
EF Core Tools
Chat
Code Explain
More Tools
How to map the discriminator column to an enum when using a TPH inheritance in EF Core?
<p>You can map a discriminator column to an enum type by first creating the enum and then mapping the <code>TPH</code> inheritance by using the enum type as a generic parameter to the <code>HasDiscriminator</code> method.</p> <p>Here is an example:</p> <pre><code class="language-csharp">public enum AnimalType { Cat, Dog } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Animal>() .HasDiscriminator<AnimalType>("DiscriminatorColumnName") .HasValue<Cat>("Cat") .HasValue<Dog>("Dog"); } </code></pre>
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
?