2013-02-19 5 views
1

У меня есть следующие модели:SQLException: несколько каскадных путей?

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.

ответ

1

С каскадом удаления по умолчанию, удаление пользователя имеет два каскадных пути - ЗапросилиBy и СозданоБыло

Отключение каскадного удаления отображается в this вопрос.

Смежные вопросы