简体   繁体   English

错误:引入FOREIGN KEY约束可能会导致循环或多个级联路径

[英]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.

相关问题 错误:引入FOREIGN KEY约束可能会导致循环或多个级联路径-为什么? - Error: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths - why? SQL 错误:引入 FOREIGN KEY 约束可能会导致循环或多个级联路径。 实体框架核心 - SQL Error: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths. Entity Framework Core 在表table上引入FOREIGN KEY约束键可能会导致循环或多个级联路径。 指定ON DELETE…错误 - Introducing FOREIGN KEY constraint key on table table may cause cycles or multiple cascade paths. Specify ON DELETE … Error 当不需要属性时,引入外键约束可能会导致循环或多个级联路径 - Introducing Foreign Key Constraint may cause cycles or multiple cascade paths when property is not required ef核心2-在表&#39;Y&#39;上引入FOREIGN KEY约束&#39;X&#39;可能会导致循环或多个级联路径 - ef core 2 - Introducing FOREIGN KEY constraint 'X' on table 'Y' may cause cycles or multiple cascade paths 在表上引入外键约束可能会导致循环或多个级联路径 - Introducing Foreign key Constraint on table may cause cycles or multiple cascade paths 在表“模型”上引入FOREIGN KEY约束“列”可能会导致循环或多个级联路径 - Introducing FOREIGN KEY constraint 'Column' on table 'Model' may cause cycles or multiple cascade paths 实体框架:在表 '' 上引入 FOREIGN KEY 约束 '' 可能会导致循环或多个级联路径 - Entity Framework: Introducing FOREIGN KEY constraint '' on table '' may cause cycles or multiple cascade paths 引入FOREIGN KEY约束可能会导致EF Core中的循环或多个级联路径 - Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths in EF Core 避免“引入FOREIGN KEY约束可能会导致循环或多个级联路径” - Avoiding 'Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM