EntityCollection.ToList().Clear()
Does not clear the entity collection. Any idea why?
Any solution?
How should i clear the EntityCollection?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
ToList()creates a copy of the EntityCollection as aList<T>and then you just clear that list and not theEntityCollectionitself.Edit 1:
Use the
Clear()method from EntityCollection:http://msdn.microsoft.com/de-de/library/bb302707.aspx
Edit 2:
Oh I see. So it’s this class: http://msdn.microsoft.com/de-de/library/ff422654(v=vs.91).aspx ?
Seems you have to enumerate all items and delete them one by one.
Here you need
ToList()to create a copy because most of the collection classes don’t like it when you delete items from them during enumeration.