पर इकाई फ्रेमवर्क मुझे इकाई फ्रेमवर्क 4.1 में संबंधित पंक्तियों को हटाने में समस्या है।हटाए गए कैस्केड
ALTER TABLE [dbo].[BookFormats] WITH CHECK ADD CONSTRAINT [FK_BookFormats_Book]
FOREIGN KEY([BookID]) REFERENCES [dbo].[Book] ([BookID]) on delete cascade
edmx संपत्ति
तो: मैं संबंधों
पुस्तक 1 < ---> * BookFormats
मैं नष्ट झरना पर स्थापित किया है के साथ टेबल है , मैं अपने Book
ऑब्जेक्ट से संबंधित सभी BokFormats
आइटमों को हटाना चाहता हूं:
var originalBook = m.db.Book.First(x => x.BookID == bookId);
originalBook.BookFormats.Clear();
m.db.SaveChanges();
लेकिन, मुझे त्रुटि मिलती है:
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.
मैं कैसे इन वस्तुओं को हटाने के लिए पर विचारों से बाहर भाग गया। कोई विचार?
तो मैं त्रुटि मिलती है: संग्रह संशोधित किया गया था; गणना ऑपरेशन निष्पादित नहीं हो सकता है। – Tony
@ टोनी, कोड में परिवर्तन की जांच करें। सबसे सुंदर तरीका नहीं है, लेकिन काम पूरा हो जाता है। – bdparrish