Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong> Split table to more than two entities in code first is very problematic. It works without any problem when using EDMX.</p> <p>To make it work you must ensure that each entity used to split table has valid one-to-one relation with all other entities used to split table. That also means spoiling your model with navigation properties and moreover ensuring that during save all navigation properties pointing to the same entity type reference the same instance (otherwise you will get exception during call to <code>SaveChanges</code>).</p> <p>So the solution for your example should be something like:</p> <pre><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 virtual CampaignFeedback Feedback {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;CampaignSurvey&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> <p>I'm even not sure how this will work in the real scenario. You can find some other problems when using it. </p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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