我有以下模型:
public class Job
{
[Key]
public int JobId { get; set; }
public string Description { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? DueDate { get; set; }
public int JobIdentity { get; set; }
[MaxLength(50, ErrorMessage = "Please ensure the Job Title is less than 50 characters")]
public string JobTitle { get; set; }
public int Priority { get; set; }
// Relationships
[ForeignKey("Category")]
public int CategoryId { get; set; }
[ForeignKey("JobType")]
public int JobTypeId { get; set; }
[ForeignKey("UserRequestedBy")]
public int RequestedBy { get; set; }
[ForeignKey("UserCreatedBy")]
public int CreatedBy { get; set; }
// Navigation Properties
public virtual JobType JobType { get; set; }
public virtual Category Category { get; set; }
public virtual User UserRequestedBy { get; set; }
public virtual User UserCreatedBy { get; set; }
public virtual ICollection<Task> Tasks { get; set; }
public virtual ICollection<JobNote> Notes { get; set; }
}
但是当我尝试运行我的应用程序时,出现以下错误:
Introducing FOREIGN KEY constraint 'FK_dbo.Jobs_dbo.Users_CreatedBy' on table 'Jobs' 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.