DCSIMG
Delete object in Entity Framework - שלמה גולדברג (הרב דוטנט)

שלמה גולדברג (הרב דוטנט)

מרצה בסלע ויועץ בעולם ה - net.

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));

פורסם: Apr 24 2010, 11:28 PM by Shlomo | with no comments
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 6 and 5 and type the answer here:


Enter the numbers above: