4
EntityCollection.ToList().Clear()

Does not clear the entity collection. Any idea why?

Any solution?

How should i clear the EntityCollection?

2 Answers 2

4

Because ToList() creates a copy of the EntityCollection as a List<T> and then you just clear that list and not the EntityCollection itself.

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.

foreach( var item in EntityCollection.ToList() )
    EntityCollection.Remove(item);

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.

4
  • EntityCollection does not have Clear()
    – ove
    May 2, 2012 at 5:50
  • As I said with the Clear() method from EntityCollection. Just postet the msdn link. May 2, 2012 at 5:50
  • The EntityCollection is part of this namespace: System.ServiceModel.DomainServices.Client.Entity .. DO not have Clear()
    – ove
    May 2, 2012 at 5:53
  • Then it's not the ADO.NET EF although the classes have the same name and simelar members. Think about retagging your question with stackoverflow.com/questions/tagged/wcf-ria-services May 2, 2012 at 6:10
0

ToList() generates a new list (you are clearing that).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.