Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to separate large table into multiple discrete types using EF-Code-First
    primarykey
    data
    text
    <p>I am trying to separate a large table into multiple discrete types.</p> <p>I'm following the example here: <a href="http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx?CommentPosted=true#commentmessage" rel="nofollow">http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx?CommentPosted=true#commentmessage</a></p> <p>It's working for a primary type and a sub-type, but does not work when I employ multiple types. I received an error </p> <blockquote> <p><em>The Entity types 'CampaginFeedback' and 'CampaignSurvey' cannot share table 'Campaign' because they are not int he same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them.</em></p> </blockquote> <p>Here are simplified versions of my classes:</p> <pre class="lang-cs prettyprint-override"><code>public class Campaign { [Key] public int CampaignId {get;set;} public string Name {get;set;} public virtual CampaignSurvey Survey {get;set;} public virtual CampaignFeedback Feedback {get;set;} } public class CampaignSurvey { [Key] public int CampaignId {get;set;} public string Question {get;set;} public string Answer {get;set;} } public class CampaignFeedback { [Key] public int CampaignId {get;set;} public string Feedback {get;set;} } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;(); modelBuilder.Entity&lt;Campaign&gt;().HasRequired(c =&gt; c.Survey).WithRequiredPrincipal(); modelBuilder.Entity&lt;Campaign&gt;().HasRequired(c =&gt; c.Feedback).WithRequiredPrincipal(); modelBuilder.Entity&lt;Campaign&gt;().ToTable("Campaign"); modelBuilder.Entity&lt;CampaignSurvey&gt;().ToTable("Campaign"); modelBuilder.Entity&lt;CampaignFeedback&gt;().ToTable("Campaign"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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