Vote count:
0
My app makes use of 3 interelated cross-reference tables - legacy versions of which have worked fine for quite a while. I'm refactoring and am at the point where I'm attempting an EF Migration (Auto - 6.1.0) and am getting hung up on:
Multiple identity columns specified for table 'RegTypesGroup'. Only one identity column per table is allowed.
I'm extensively commented out various parts of the Fluent Mapping files hoping to find out which one is causing the 2nd identity column to be created. No joy but as I step thru various options I'm finding that the error messages tossed out of the EF migration engine don't really comport to the changes of the code. I'm suspecting 'false negatives'.
Clearly there's a high probability of error in my code - and I'm not doing anyone any favors (exception my own selfish self) by bucking the convention of Primary Key but I'm committed to the pattern of:
idTableName
And have verified that the fluent syntax is present.
I need better ideas of how to coax better error messages out of the migrator.
At the root of everything is the single 'RegType' (Type of Registration aka Option)
public partial class RegType
{
public int idRegType { get; set; }
public string OptionExplain { get; set; }
public string OptionLabel { get; set; }
public double Price { get; set; }
public int SortOrder { get; set; }
}
and the mapping:
public RegTypeMap()
{
// Primary Key
HasKey(t => t.idRegType);
// Table & Column Mappings
ToTable("RegType");
Property(t => t.idRegType).HasColumnName("idRegType");
Property(t => t.OptionExplain).HasColumnName("RegTypeExplain");
Property(t => t.OptionLabel).HasColumnName("RegTypeLabel");
Property(t => t.Price).HasColumnName("Price");
Property(t => t.SortOrder).HasColumnName("SortOrder");
}
Individual RegTypes are aggregated into discrete and defined groups. A crosstab exists to group individual RegTeypes into one or another group:
public partial class RegTypesXref
{
public int idRegTypesXref { get; set; }
public int idRegTypesGroup { get; set; }
public int idRegType { get; set; }
public virtual RegType RegType { get; set; }
public virtual RegTypesGroup RegTypesGroup { get; set; }
}
public RegTypesXrefMap()
{
// Primary Key
HasKey(t => t.idRegTypesXref);
//// Properties
//// Table & Column Mappings
ToTable("RegTypesXref");
Property(t => t.idRegTypesXref).HasColumnName("idRegTypesXref");
Property(t => t.idRegTypesGroup).HasColumnName("idRegTypesGroup");
Property(t => t.idRegType).HasColumnName("idRegType");
//// Relationships
//fwiw, this commented-out relation worked in legacy but syn-errors on the update.
//this.HasRequired(t => t.RegType)
// .WithMany(t => t.RegTypeXrefs)
// .HasForeignKey(d => d.idRegType);
HasRequired(t => t.RegTypesGroup)
.WithMany(t => t.RegTypesXrefs)
.HasForeignKey(d => d.idRegTypesGroup);
}
Because multiple Groups exist - another crosstab:
public partial class RegTypesGroupsXref
{
public int idWebinarRegTypesGroup { get; set; }
public int idWebinar { get; set; }
public int idRegTypesGroup { get; set; }
public virtual RegTypesGroup RegTypesGroup { get; set; }
public virtual Webinar Webinar { get; set; }
}
public class RegTypesGroupsXrefMap : EntityTypeConfiguration<RegTypesGroupsXref>
{
public RegTypesGroupsXrefMap()
{
// Primary Key
HasKey(t => t.idWebinarRegTypesGroup);
// Properties
// Table & Column Mappings
ToTable("RegTypesGroupsXref");
Property(t => t.idWebinarRegTypesGroup).HasColumnName("idWebinarRegTypesGroup")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.idWebinar).HasColumnName("idWebinar");
Property(t => t.idRegTypesGroup).HasColumnName("idRegTypesGroup");
// Relationships
HasRequired(t => t.RegTypesGroup)
.WithMany(t => t.RegTypesGroupsXrefs)
.HasForeignKey(d => d.idRegTypesGroup);
//this.HasRequired(t => t.Webinar)
// .WithRequiredDependent(t => t.RegTypesGroup)
// .HasForeignKey(d => d.);
}
}
And at the top-level support of instantiating an individual Group:
public partial class RegTypesGroup
{
public int idRegTypesGroup { get; set; }
public string RegTypesGroupDesc { get; set; }
public int SortOrder { get; set; }
public virtual ICollection<RegTypesGroupsXref> RegTypesGroupsXrefs { get; set; }
public virtual ICollection<RegTypesXref> RegTypesXrefs { get; set; }
}
public RegTypesGroupMap()
{
// Primary Key
HasKey(t => t.idRegTypesGroup);
// Properties
Property(t => t.RegTypesGroupDesc)
.HasMaxLength(50);
// Table & Column Mappings
ToTable("RegTypesGroup");
Property(t => t.idRegTypesGroup).HasColumnName("idRegTypesGroup")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(t => t.RegTypesGroupDesc).HasColumnName("RegTypesGroupDesc");
Property(t => t.SortOrder).HasColumnName("SortOrder");
}
}
Aucun commentaire:
Enregistrer un commentaire