I'm still getting my head around using EF. I using a code first approach in my project and stumbled upon the following issue.
I have the following objects:
public class Employee
{
public int EmployeeId { get; set; }
public int BusinessUnitId { get; set; }
public virtual BusinessUnit BusinessUnit { get; set; }
}
public class Quote
{
public int QuoteId { get; set; }
[DisplayName("Business Unit")]
public int BusinessUnitId { get; set; }
[DisplayName("Responsible Employee")]
public int EmployeeId { get; set; }
[DisplayName("Date Issued")]
[DataType(DataType.Date)]
public DateTime DateIssued { get; set; }
[DataType(DataType.MultilineText)]
public string Description { get; set; }
public virtual Employee Employee { get; set; }
public virtual BusinessUnit BusinessUnit { get; set; }
}
Both include a BusinessUnit property, and it seems that EF doesn't want to allow this. Seeing that I get the following error below on the Index() method when a Linq query with a bunch of includes are executed.
Introducing FOREIGN KEY constraint 'FK_dbo.Quotes_dbo.BusinessUnits_BusinessUnitId' on table 'Quotes' 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.
Can someone please explain to me why I get this error and how I might go about fixing it. Thanks.
EDIT:
This is definitly caused by including the BusinessUnit property in both the Quote object and the Employee object. I just dont understand why.
EDIT 2:
The code for the BusinessUnit class:
public class BusinessUnit
{
public int BusinessUnitId { get; set; }
public string Name { get; set; }
}