Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to tell Code First how these classes relate to tables. There are three options:</p> <ul> <li><p><strong>Table per type (TPT)</strong> would mean the fields defined on Fund and InvestorFund would go into their own tables and properties defined on BaseEntity would go to a table named BaseEntity. Querying would be slower as each entity now has to combine the fields from multiple tables. </p> <pre><code>modelBuilder.Entity&lt;Fund&gt;().ToTable("Funds"); modelBuilder.Entity&lt;InvestorFund&gt;().ToTable("InvestorFunds"); </code></pre></li> <li><p><strong>Table per heirarchy (TPH)</strong> would mean that Fund, InvestorFund and BaseEntity properties would all be merged into a single table named BaseEntity and an extra field would be required to indicate which row is which type. This extra field is called the <em>discriminator</em>.</p> <pre><code>modelBuilder.Entity&lt;BaseEntity&gt;() .Map&lt;Fund&gt;(m =&gt; m.Requires("Discriminator").HasValue("F")) .Map&lt;InvestorFund&gt;(m =&gt; m.Requires("Discriminator").HasValue("I")); </code></pre></li> <li><p><strong>Table per concrete type (TPC)</strong> would mean that Fund and InvestorFund each have their own table which would also include any fields needed for their base classes.</p> <pre><code>modelBuilder.Entity&lt;Fund&gt;().Map(m =&gt; { m.MapInheritedProperties(); m.ToTable("Funds"); }); modelBuilder.Entity&lt;InvestorFund&gt;().Map(m =&gt; { m.MapInheritedProperties(); m.ToTable("InvestorFunds"); }); </code></pre></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload