[英]Error: introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths
A quick question for masters. 大师们的一个快速问题。
I got 2 EF model classes: 我有2个EF模型类别:
public class School
{
public int Id { get; set; }
[DisplayName("School")]
public string Name { get; set; }
public List<Teacher> Teachers { get; set; }
public List<Note> Notes { get; set; }
}
public class Teacher
{
public int Id { get; set; }
[DisplayName("Öğretmen")]
public string Name { get; set; }
public int SchoolId { get; set; }
public School School { get; set; }
public List<Note> Notes { get; set; }
}
Basically I want to create an one to many relationship in code-first. 基本上,我想以代码优先创建一对多关系。
But when I try to do that, I get this error: 但是,当我尝试这样做时,出现此错误:
Introducing FOREIGN KEY constraint 'FK_dbo.Teachers_dbo.Schools_SchoolId' on table 'Teachers' may cause cycles or multiple cascade paths.
在表“教师”上引入外键约束“ FK_dbo.Teachers_dbo.Schools_SchoolId”可能会导致循环或多个级联路径。 Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。
Where have I made a mistake? 我在哪里弄错了?
EDIT 编辑
public class Note
{
public int Id { get; set; }
[Required,DisplayName("Başlık"), StringLength(50)]
public string Title { get; set; }
[Required,DisplayName("Açıklama"), StringLength(4000)]
public string Description { get; set; }
public string File { get; set; }
public DateTime UploadDate { get; set; }
public bool IsApproved { get; set; }
public int SchoolId { get; set; }
public int OwnerId { get; set; }
public int TeacherId { get; set; }
//Keys
public School School { get; set; }
public Teacher Teacher { get; set; }
public List<Comment> Comments { get; set; }
}
I didnt get any error for this Model and Keys.. 我没有收到任何关于此型号和钥匙的错误。
Remove the relationship from Note to School and vice versa. 从“注释”到“学校”之间删除关系,反之亦然。 You could get the school by the teacher that has a relationship to the note.
您可以由与笔记有关系的老师上学。
It will produce your issue. 它将产生您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.