Unable to update the EntitySet '[TableName]' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation
היה לי בבסיס הנתונים קישור פשוט של רבים לרבים
מבחינת האובייקטים ב - Entity Framework זה נוצר בצורה הזאת
הקשר בין הרצאה לתגים הוא רבים לרבים. כשניסיתי לכתוב את הקוד הזה
Lecture lecture = entities.Lectures.First();
Tag tag = new Tag() { Name = "acbd" };
lecture.Tags.Add(tag);
entities.SaveChanges();
קבלתי את ההודעה הבאה
Unable to update the EntitySet 'TagLecture' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation
התחלתי לחקור את הנושא
ופתחתי את קובץ ה - xml שה - EF מייצר.
וראיתי את ההודעה הבאה
<!--Errors Found During Generation:
warning 6002: The table/view 'SCO.dbo.TagLecture' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
מסתבר שלא היה בטבלת הקשר TagLecture אף מפתח ראשי. הגדרתי את שני העמודות כמפתח ראשי רפרשתי את המודל והכול בא על מקומו בשלום