I am trying to separate a large table into multiple discrete types.
I'm following the example here: http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx?CommentPosted=true#commentmessage
It's working for a primary type and a sub-type, but does not work when I employ multiple types. I received an error
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.
Here are simplified versions of my classes:
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<PluralizingTableNameConvention>();
modelBuilder.Entity<Campaign>().HasRequired(c => c.Survey).WithRequiredPrincipal();
modelBuilder.Entity<Campaign>().HasRequired(c => c.Feedback).WithRequiredPrincipal();
modelBuilder.Entity<Campaign>().ToTable("Campaign");
modelBuilder.Entity<CampaignSurvey>().ToTable("Campaign");
modelBuilder.Entity<CampaignFeedback>().ToTable("Campaign");
}