I'm continuing my venture with Entity Framework, but now I'm stuck again. I've two small classes:
public class Machine
{
public int MachineID { get; set; }
public string Name { get; set; }
[Required]
[ForeignKey("InstalledByID")]
public virtual Employee InstalledBy { get; set; }
public int InstalledByID { get; set; }
[Required]
[ForeignKey("LastServicedID")]
public virtual Employee LastServiced { get; set; }
public int LastServicedID { get; set; }
}
public class Employee
{
public int EmployeeID { get; set; }
public string Name { get; set; }
}
I'm trying to set two properties: InstalledBy and LastServiced. Both of these properties are instances of an Employee class. Additionally, I could care less that there are two REVERSE properties on the Employee class that tells a list of machines installed as well as machines repaired. When I try to Update-Database after a Migration, I get an error. I thought the ForeignKeyAttribute was the key, but apparently it's not working for me. Here is the error:
Introducing FOREIGN KEY constraint 'FK_dbo.Machines_dbo.Employees_InstalledByID' on table 'Machines' 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. See previous errors.
Also, I've tried dabbling in the OnModelCreating and FluentAPI, but my attempts did not work. Any pointers as to what I'm doing wrong and how to fix it would be greatly appreciated. Thank you, all.