You should just be able to use: public static void RemoveEach(this EntityCollection collectionToEmpty) where T : class { if (!collectionToEmpty. IsLoaded) collectionToEmpty.Load(); while (collectionToEmpty.Any()) collectionToEmpty. Remove(collectionToEmpty.First()); } That's the only constraint that EntityCollectionI haven't used EF for a while, so it's not entirely obvious.
You should just be able to use: public static void RemoveEach(this EntityCollection collectionToEmpty) where T : class { if (!collectionToEmpty. IsLoaded) collectionToEmpty.Load(); while (collectionToEmpty.Any()) collectionToEmpty. Remove(collectionToEmpty.First()); } That's the only constraint that EntityCollection requires, and you're not using anything within the method body which needs EntityObject.By the way, is what you're doing here very different to calling collectionToEmpty.Clear()?
I haven't used EF for a while, so it's not entirely obvious...
Yay, my first personal drive-by Skeeting! ;) Ok, thanks for the info, I also take your answer to mean generics ARE required. Regarding "is it different", .Clear() would require multiple calls to context.SaveChanges(), effectively preventing me from implementing this sugar without supporting multiple concurrently contexts.As I understand it, the method shown here will behave properly this way, but I'll report back... – shannon Mar 20 at 7:54.
The same, when calling with a specific (non-generic) derived type. Do I have to do use the following signature? If so, intellisense or the compiler should warn me about using an abstract class as the generic type-specifier in this method, because I've just created an un-callable method, no?
And if you don't mind, would you please point out why this is so (e.g. A scenario where type-safety would be broken or confusion would result if it were allowed).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.