【发布时间】:2021-05-06 13:31:39
【问题描述】:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
public int MainCourseId { get; set; }
public Course MainCourse { get; set; }
public IList<StudentCourse> StudentCourses { get; set; }
}
public class Course
{
public int Id { get; set; }
public string CourseName { get; set; }
public string Description { get; set; }
}
public class StudentCourse
{
public int StudentId { get; set; }
public Student Student { get; set; }
public int CourseId { get; set; }
public Course Course { get; set; }
}
有两个问题。 第一个问题是,上面的迁移没有创建 MainCourseId ,给出了这个错误。 “在表 'Students' 上引入 FOREIGN KEY 约束 'FK_Students_Courses_MainCourseId' 可能会导致循环或多个级联路径。指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。 无法创建约束或索引。查看以前的错误。”
其次,在另一个实体结构相同的系统中,使用 MainCourseId 中的修改值更新现有记录不起作用。
【问题讨论】:
标签: c# entity-framework .net-core entity-framework-core ef-core-5.0