I need a structure in EF6 where the Item Color can have multiple translations. Would this structure support that functionality and is it correct?
I am attempting to apply the following relationships:
- Each PIMItem has 1 PIMColor
- Each PIMColor can have multiple PIMColorTranslations
- Only 1 PIMColorTranslation per Color per LanguageCode is allowed.
[Table("PIMItem")]
public class PIMItem
{
[Key]
public string Id {get;set;}//RowKey no.
//there are additional columns in this item not related to color
[ForeignKey("PIMColor")]
[Column(Order=3)]
public string ColorId {get;set;}
public PIMColor PIMColor {get;set;}
}
[Table("PIMColor")]
public class PIMColor
{
[Key]
public string ColorId {get;set;}
public ICollection<PIMItem> PIMItems {get;set;}
public ICollection<PIMColorTranslation> PIMColorTranslation {get;set;}
}
[Table("PIMColorTranslation")]
public class PIMColorTranslation{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Column(Order=1)]
public int Id {get;set;}
[ForeignKey("PIMLanguage")]
[Column(Order=2)]
public string LanguageCode {get;set;}
[ForeignKey("PIMColor")]
[Column(Order=3)]
public string ColorId {get;set;}
public string Translation {get;set;}
}
[Table("PIMLanguage")]
public class PIMLanguage{
[Key]
public string LanguageCode {get;set;}
public string Language {get;set;}
public ICollection<PIMColorTranslation> PIMColorTranslation {get;set;}
}
public class SharedCtxt : DbContext
{
public SharedCtxt() : base(sharedData.conn_string)
{
}
public DbSet<PIMLanguage> PIMLanguages {get;set;}
public DbSet<PIMColor> PIMColors {get;set;}
public DbSet<PIMColorTranslation> PIMColorTranslations {get;set;}
public DbSet<PIMItem> PIMItems {get;set;}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}