We use code-first EF 4 with DbContext and DbSet<> and POCOs with DataAnnotations.
I am new to this and cannot seem to find an answer to my quesiton:
How can I delete multiple items from the DB directly without first selecting the items with LINQ and then doing loop and call Remove(item) on each iteration? That seems silly to me.
All references concerning this refer to function that don’t seem to exist, like DeleteOnSubmit(item) which isn’t there in my DbContext. Also, it only deletes ONE item.
Is there a better way?
DeleteOnSubmitis function fromDataContextclass = Linq-to-SQLYo don’t have to load item before you delete it. It is enough if you know its key. Something like this should work:
or
There is no way to delete multiple items with EF (except cascade delete) without specifying each single item to be deleted. If you want to deleted multiple items directly you must use SQL like