Вот мои упрощенные модели:
Код: Выделить всё
public class Student
{
public int Id { get; set; }
public int SchoolId { get; set; }
// Navigation property to many-to-many relationship
public ICollection Courses { get; set; }
}
public class Course
{
public int Id { get; set; }
public ICollection Students { get; set; }
}
public class StudentCourseLink
{
public int StudentId { get; set; }
public Student Student { get; set; }
public int CourseId { get; set; }
public Course Course { get; set; }
}
Код: Выделить всё
INSERT INTO StudentCourseLinks (StudentId, CourseId)
SELECT s.Id, 1
FROM Students s
WHERE s.SchoolId = 1;
Есть ли способ выполнить эту массовую вставку с помощью Entity Framework Core, сохраняя безопасность типов и избегая необработанного SQL?< /p>
Будем очень признательны за любые рекомендации или решения по этому поводу!
Подробнее здесь: https://stackoverflow.com/questions/790 ... -core-with