i have many classes but in PorductionLine
and Machine
I have some problems. ProductionLine Class is:
[Column("FldKeyId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
[Key]
public int MyKeyId { get; set; }
[Column("FldCode")]
[Required]
[Index(IsUnique = true)]
public int MyCode
{
get { return _Code; }
set { _Code = value; }
}
[Column("FldName")]
[Required]
public string MyName
{
get { return _Name; }
set { _Name = value; }
}
[Column("FldLocation")]
[Required]
public string MyLocation
{
get { return _Location; }
set { _Location = value; }
}
[Column("FldCompanyKey")]
public int MyCompanyKey { get; set; }
[ForeignKey("MyCompanyKey")]
[Required]
public virtual Company Company { get; set; }
And Machine Class is:
[Column("FldKeyId")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
[Key]
public int MyKeyId { get; set; }
[Column("FldCode")]
[Required]
[Index(IsUnique = true)]
public int MyMachineCode
{
get { return _MachineCode; }
set { _MachineCode = value; }
}
[Column("FldName")]
[Required]
public string MyName
{
get { return _Name; }
set { _Name = value; }
}
[Column("FldProductionLineKey")]
public int MyProductionLineKey { get; set; }
[ForeignKey("MyProductionLineKey")]
//[Required]
public ProductionLine ProductionLine { get; set; }
when I want generate database form this classes I have this error:
Introducing FOREIGN KEY constraint 'FK_dbo.TblMachine_dbo.TblProductionLine_FldProductionLineKey' on table 'TblMachine' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors. when I comment this 3 lines
[Column("FldProductionLineKey")]
public int MyProductionLineKey { get; set; }
[ForeignKey("MyProductionLineKey")]
error is gone but I want this codes cus in some other classes I have this problem... what I have to do? thanks for help!!