views:

45

answers:

1

Is it possible to clear an EntityCollection without having to Load() it?

I have code in place that uses stub entities to add new entities to an EntityCollection without having load the actual Entity I'm adding, but is there some equivalent to this when Clear()ing an EntityCollection?

A: 

No, not exactly. If you have a cascade on the FK, however, you can delete the master record without first loading the details.

Craig Stuntz
True, that is useful in some scenarios, but not in this one I don't think. Basically I have a many-to-many link table between entity A and B. So through the magic of EF A has an EntityCollection of Bs. But to clear the Bs from an A I have to hit the database to load all the Bs into memory before I can clear it... Just seems inefficient and I was wondering if there was a way to avoid that.
mutex
If you have a huge list and you're using EF 4, you can drop down to SQL with Context.ExecuteStoreCommand.
Craig Stuntz