Delete object in Entity Framework
אם תנסו למחוק אובייקט ב - collection ב - entity framework בעזרת remove בצורה הבאה
Lecture lecture = entities.Lectures.Include("SelaRelatedCourses").First();
lecture.SelaRelatedCourses.Remove(lecture.SelaRelatedCourses.ElementAt(0));
אתם יכולים לקבל הודעת שגיאה בהסגנון הזה
A relationship is being added or deleted from an AssociationSet 'FK_Relatedcourses_Lecture'. With cardinality constraints, a corresponding 'SelaRelatedCourses' must also be added or deleted.
כדי למחוק בצורה נכונה עדיף לכתוב ככה
entities.DeleteObject(lecture.SelaRelatedCourses.ElementAt(0));