I have this entity in my Domain:
public class CalibrationToolActivePart
{
[Key]
public int CalibrationToolActivePartID { get; set; }
public int CalibrationToolID { get; set; }
public int CalibrationToolTypePartID { get; set; }
public int MeasureUnitID { get; set; }
[ForeignKey("CalibrationToolID")]
[ScriptIgnore(ApplyToOverrides=true)]
public virtual CalibrationTool CalibrationTool { get; set; }
[ForeignKey("CalibrationToolTypePartID")]
[ScriptIgnore(ApplyToOverrides = true)]
public virtual CalibrationToolTypePart CalibrationToolTypePart { get; set; }
[ForeignKey("MeasureUnitID")]
[ScriptIgnore(ApplyToOverrides = true)]
public virtual MeasureUnit MeasureUnit { get; set; }
public int? ToleranceID { get; set; }
//TODO: Tolerance outra tabela
[ForeignKey("ToleranceID")]
public virtual Tolerance Tolerance { get; set; }
public bool Active { get; set; }
}
And the one that sends the foreign key:
public class Tolerance
{
[Key]
public int ToleranceID { get; set; }
[Display(Name = "Nome")]
[Required(ErrorMessage = "O campo \"Nome\" deve ser preenchido")]
public string Name { get; set; }
[Required(ErrorMessage = "O campo \"Tipo\" deve ser selecionado")]
public int MeasureTypeID { get; set; }
[ForeignKey("MeasureTypeID")]
public virtual MeasureType MeasureType { get; set; }
[Required(ErrorMessage = "O campo \"Unidade\" deve ser selecionado")]
public int MeasureUnitID { get; set; }
[ForeignKey("MeasureUnitID")]
public virtual MeasureUnit MeasureUnit { get; set; }
[Required(ErrorMessage = "O campo \"Máximo Permitido\" deve ser preenchido")]
public int CompanyID { get; set; }
[Required(ErrorMessage = "O campo \"Mínimo\" deve ser preenchido")]
public double Minimum { get; set; }
[Required(ErrorMessage = "O campo \"Máximo\" deve ser preenchido")]
public double Maximum { get; set; }
public bool Inactive { get; set; }
[ScriptIgnore(ApplyToOverrides=true)]
public virtual ICollection<CalibrationToolActivePart> CalibrationToolActiveParts { get; set; }
public double MaximumAllowed { get; set; }
[Required(ErrorMessage = "O campo \"Total\" deve ser preenchido")]
public double Total { get; set; }
}
The mapper module looks like this:
internal class CalibrationConfiguration : EntityTypeConfiguration<Calibration>
{
public CalibrationConfiguration()
{
HasRequired<CalibrationTool>(x => x.CalibrationTool)
.WithMany(x => x.Calibrations)
.HasForeignKey(x => x.CalibrationToolID);
HasMany<File>(x => x.StandardCertificationFiles)
.WithMany(x => x.Calibrations)
.Map(m =>
{
m.ToTable("Calibrations_Files");
m.MapLeftKey("CalibrationID");
m.MapRightKey("FileID");
});
HasMany<CalibrationTool>(x => x.CalibrationToolsUsed)
.WithMany()
.Map(m =>
{
m.ToTable("Calibrations_CalibrationTools");
m.MapLeftKey("CalibrationID");
m.MapRightKey("CalibrationToolID");
});
}
this is the other one:
internal class ToleranceConfiguration : EntityTypeConfiguration<Tolerance>
{
public ToleranceConfiguration()
{
HasMany<CalibrationToolActivePart>(x => x.CalibrationToolActiveParts)
.WithOptional(x => x.Tolerance)
.HasForeignKey(x => x.ToleranceID);
}
}
I just have to leave N for N and I can not do this, you need more information just to comment what I'm putting.